I am currently building a mobile(Android) app that is a search engine for products. The products information, is currently stored in a WordPress eCommerce store(WooCommerce). I have added 5 sample products to this store for testing purposes.
I currently have the search function working inside the app. The MySQL query used for this search is as follows:
SELECT a.*, b.guid AS img_url
FROM wp_posts AS a
LEFT JOIN wp_posts AS b ON a.ID = b.post_parent
WHERE a.post_type='product'
AND a.post_title LIKE '%$search%'
Now, when I search for something like “sample”, I get my search results with all of the products that contain the word sample in it’s title.
However, if one of those products has more than one image attached to it. I get results for as many images that are attached to the product.(see screenshot below)
Screenshot: http://cl.ly/M7Ap
If anyone could help me with this, so that I don’t get the multiple results for the one post. It would be greatly appreciated.
If you don’t care about which result, but just want one per post, can you not just use GROUP BY?