Query to SELECT posts based on category
-
Dear all,
I am using the following query to retrieve entries based on their category (actually their
wp_term_taxonomy.term_id). However, even if I use the DISTINCT keyword, I obtain duplicate entries when several categories, for instance here 20 and 26, applies to the same entry. How should I do it?SELECT DISTINCT * FROM wp_posts<br>
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)<br>
LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)<br>
WHERE wp_posts.post_status = 'publish'<br>
AND wp_term_taxonomy.taxonomy = 'category'<br>
AND wp_term_taxonomy.term_id IN (5, 20, 26)<br>
ORDER BY post_date DESC<br>
LIMIT 5
- The topic ‘Query to SELECT posts based on category’ is closed to new replies.