Wordpress: Find posts in category 1 and not in category 2 -
I have two categories, see and hide ...
I list all these posts Wish scene sequence, which is quite easy. However, due to user error (or inspection) there may be some posts that are in both categories.
How can I pull those positions which are in the visual category, but not in the hidden category?
Here's my current solution. I'm not sure the get_posts method is the least expensive option I can use ...
$ cat = get_cat_ID ( 'Visible'); $ Cat2 = get_cat_ID ('HideMe'); $ Myposts = get_posts (array ('cat' = & gt; "$ cat, - $ cat2", 'showposts' => 5)); If not ($ myposts) {// do something}
I'm not sure Get_posts, But did you check the query_posts?
See
It works the same as get_posts, not sure it is less expensive, but give it a try
$ Catnow = 13; // replace with category id that you want to draw $ exception = ', -19, -18'; // Replace with Category ID that you want to exclude $ post_args = array ('cat' = & gt; $ catnow. $ Exception); Query_posts ($ post_args); If (is_pause ()): while (is_pause ()): the_post (); // Do something in the following steps; Else: // No posts were found;
Comments
Post a Comment