Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Bainternet

    (@bainternet)

    Out of the box its only changing the main query.

    changing a custom query requires custom coding.

    ex:

    add_action('pre_get_posts','custom_pre_get_posts');
    function custom_pre_get_posts($q){
       	if ($q->is_category('board-of-directors')){
       		$t = get_term_by( 'slug', 'board-of-directors', 'category');
       		if ($t){
    			$order  = $GLOBALS['in_cat_order']->get_all_category_posts($t->term_id);
    			if (count($order)> 0 ){
    				$q->set('post__in',$order);
    				$q->set('orderby','post__in');
    			}
    		}
    	}
    }
    Thread Starter Dan

    (@danjsouther)

    I added that code and got the error,

    Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

    I was able to trace it to your plugin.php file

    function get_all_category_posts($cat_id = null){
    			if ($cat_id == null) return array();
    			$cat_meta = get_option( "in_category");
        		$order = isset($cat_meta[$cat_id])? $cat_meta[$cat_id]: array();
        		$posts = get_posts(array(
        			'post_type' => 'post',
        			'posts_per_page' => -1,
        			'post__not_in' => $order,
        			'fields' => 'ids',
        			'cat' => $cat_id
        			)
        		);
        		foreach ((array)$posts as $p) {
        			$order[] = $p;
        	}
        	return $order;
    }

    after removing ‘cat’ => $cat_id the error went away.

    Thread Starter Dan

    (@danjsouther)

    Of course that creates problems elsewhere so for a quick fix I made a copy of that function without the problematic array entry for the custom_pre_get_post() to use.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order is not changed in category loop’ is closed to new replies.