tags:

views:

61

answers:

1

I have two categories, visible and hideMe...

I want to list all posts in the visible category, which is easy enough. However, due to user error (or oversight) there may be some posts which are in both categories.

How can I pull the posts that are in the visible category but not also in the hideMe category?

Here's my current solution. I'm just not certain that the get_posts method is the least expensive option I could use...

$cat=get_cat_ID('visible');
$cat2=get_cat_ID('hideMe');
$myposts = get_posts(array('cat' => "$cat,-$cat2",'showposts' => 5));
if($myposts )
{//do something}
A: 

I'm not sure about get_posts, but have you checked out query_posts?

See Template Tags/query posts

It works the same way as get_posts, not sure if it's less "expensive" but give it a try

$catnow = 13; //replace with category id you want to pull 
$exception = ',-19,-18'; //replace with category ids you want to exclude
$post_args = array('cat'=>$catnow.$exception);
query_posts($post_args); 
if (have_posts()): while (have_posts()): the_post();
//do something to the posts
endwhile; 
else: 
//no posts found
endif;
st4ck0v3rfl0w