I have this category which is “community-posts” I don’t want it to appear on my homepage loop so I added this to my query
<?php query_posts(array('showposts' => 4,'category__not_in' => $id_communityposts,));?>
This is working fine with me but some “community-posts” I want them to be featured on the homepage loop. (exception)
so I want to only exclude the posts that has one category as “community-posts” if it has this category and more its shows normally.
First thing do not use query_posts – it should never be used as it alter the main query. Use
get_posts
instead – it’s much safer and perform the same task.To answer your question, let’s first imagine how the query would look in SQL (assuming your
$id_communityposts
is equal to 2) :So we query the post, post meta and taxonomy tables and make two possible conditions:
featured
meta key of the post is set to1
(change this to whatever key / value depending of how you store the “featured” information).For that kind of specific cases,
get_posts
isn’t really good to play with – querying the DB withWPDB
will give you much more flexibility.Let me know if you run into any issue as it is an untested query.
If I understood the question correctly , The simplest solution, not involving complicated
SQL
would be something along the lines of :read get_the_category() in codex
Along the same logic lines you could also use wp_get_post_categories