selecting multiple categories from database selecting multiple categories from database wordpress wordpress

selecting multiple categories from database


Use the IN clause:

WHERE category IN ('cat1', 'cat2', 'cat3')

Alternatively, you can use OR:

WHERE category = 'cat1'   OR category = 'cat2'   OR category = 'cat3'


Try OR in place of AND (in where condition). try this:

$query = ("SELECT blogs_id, title, body, posted_by, category FROM blogs INNER JOIN categories ON categories.category_id=blogs.category_id where category='cat1' OR category='cat2' OR category='cat3' ORDER BY blogs_id desc LIMIT 10");


Try this

$query = ("SELECT blogs_id, title, body, posted_by, category FROM blogs INNER JOIN categories ON categories.category_id=blogs.category_id where category IN ('cat1', 'cat2', 'cat3') ORDER BY blogs_id desc LIMIT 10");