Get_Posts(); – Exclude Categories

I’ve run into problems several times where exclude and include do not work, or work selectively, and as a result, either all of the posts are included, or none of them are. I’ve found an answer that works both inside and outside of the loop.

$args = array (
     'post_type' => 'post', 	 
     'posts_per_page' => 1, 	 
     'category' => -3 

$single_post = get_posts($args);

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.