• Resolved Joris van Montfort

    (@jorisvanmontfort)


    I noticed the order is not menu order when using a taxonony query. Example:

    
    $args = array(
        'posts_per_page' => -1,
        'post_type' => 'portfolio',
        'tax_query' => array(
            array(
                'taxonomy' => 'portfolio_cat',
                'field' => 'id',
                'terms' => array(5)
            )
        ),
    );
    
    $posts = get_posts($args);
    

    I’m not sure if this is the best solution, but i ended up adding this to my functions.php to fix it:

    
    add_filter( 'pre_get_posts', function( &$q ) {
    	$order = '';
    	if (isset($q->query['orderby'])) {
    		$order = $q->query['orderby']; 
    	}
    
    	if (false === strpos( $order, 'menu_order' )) {
    		$q->set( 'orderby', 'menu_order' );
    		$q->set( 'order', 'ASC' );
    	}
    });
    

    I feel this should be fixed within the plugin itself.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not working on front end with tax_query’ is closed to new replies.