WordPress.org

Ready to get started?Download WordPress

Forums

Filtering the main loop, not the sidebar (2 posts)

  1. leemon
    Member
    Posted 3 years ago #

    Hi!

    I'm using the following code to prevent posts in specific categories from appearing on front page:

    function front_page_excludes($query) {
    	if($query->is_front_page) {
    		$query->set(
    			'category__not_in',
    			array(1,2)
    		);
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'front_page_excludes');

    There's a problem with this code, though. It's affecting the recent posts widget on the sidebar, too, and I just want it to filter just the main loop, not the sidebar.

    Any ideas?

    Thanks in advance

  2. esmi
    Forum Moderator
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic