WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query mod broken in WP 3.1 (3 posts)

  1. pshero
    Member
    Posted 3 years ago #

    My functions.php file contains a query modifier for the homepage to exclude categories that I don't want appearing there. With the 3.1 upgrade this is somehow broken now. Can anyone tell me why? Here's what my code looks like in functions.php

    <?php
    function myFilter($query) {
    	if ($query->is_home) {
    		$query->set('cat','-1,-11,-12,-4,-23,-24');
    	}
    return $query;
    }
    add_filter('pre_get_posts','myFilter');
    ?>
  2. Some category excluder plugins such as Ultimate Category Excluder may be broken as well. That one is actually a bug: Trac Ticket
    The Hotfix plugin now has a fix that might help: http://wordpress.org/extend/plugins/hotfix/

  3. pshero
    Member
    Posted 3 years ago #

    Thanks lpstenu. In the Trac Ticket link I found a solution, posted below for anyone with similar issues.

    <?php
    function exclude_category($query) {
    	if ( $query->is_home ) {
    		$query->set('category__not_in', array(1,11,12,4,23,24));
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic