• Resolved AgusN

    (@agusn)


    Hello,

    I need to sort my post in category page, but my filter page got affected.
    My filter page is a page i have created from wp backend and are using page template that has looping on it to show some post based on category filter – the page has 4 dropdown box that contain some category for filter purpose.

    I just put little simple code in function.php file of my wp theme. here is the code:

    add_action('pre_get_posts', 'filterByCat');
    function filterByCat( $query )
    {
    
    	if( is_admin() )
    	{
    		return $query;
    	}
    
    	if(!is_singular()){
    		if($query->is_category()){
               	 $query->set('meta_key', 'status');
            	 $query->set('orderby', 'meta_value');
                     $query->set('order', 'DESC');
    		}
    	 }
    	return $query;
    
    }

    i use is_singular() to identify if the page rendered is not a single page, and i thought it’s enough to prevent filterByCat function executed on my filter page. but it doesn’t work. filterByCat still executed on my filter page even that page just a usual single page that using my custom page template.

    Hope somebody can help me to solve this problem,
    Thanks

  • The topic ‘Conflict query sorting in 2 pages’ is closed to new replies.