Exclude categories from featured page widget

Support Area Forums Foundation Exclude categories from featured page widget

Viewing 2 posts - 1 through 2 (of 2 total)
URL to the page in question: http://dev.clevelandvets.org
  • Author
    Posts
  • #26440
    Chris Jones
    Participant

    Hi Bill, hope you are well.

    I need to exclude some categories from the Featured Posts Widget I’m using on the home page. I assume widgets-post.php is where I alter the filter? Not sure the syntax.

    cheers c-

    #26443
    Bill Robbins
    Moderator

    Hello Chris,

    Good question. There isn’t a built in way to exclude categories, but you can do that with a bit of editing. The file you want to change is widget-posts.php and this is the section:

    
    		$query_args = array(
         			'post_type' => 'post',
         			'cat'       => $instance['posts_cat'],
         			'showposts' => $instance['posts_num'],
         			'orderby'   => $instance['orderby'],
         			'order'     => $instance['order'],
         		);
    

    Those are the arguments for a wp_query instance that the widget runs. WP Query has lots of options in it (http://codex.wordpress.org/Class_Reference/WP_Query). You probably want something like this:

    
    'category__not_in' => array( 2, 6 )
    

    which lets you exclude categories by ID. That would change the above code to something like this:

    
    		$query_args = array(
         			'post_type' => 'post',
         			'cat'       => $instance['posts_cat'],
         			'showposts' => $instance['posts_num'],
         			'orderby'   => $instance['orderby'],
         			'order'     => $instance['order'],
         			'category__not_in' => array( 2, 6 ),
         		);
    

    Where 2 and 6 are the ID’s of the categories you want to leave out.

    See how that works for you.

    Enjoy your Saturday,
    Bill

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Exclude categories from featured page widget’ is closed to new replies.