• Resolved gaspas

    (@arti)


    I have a custom taxonomy, and I want to allow user to click and change order, I’am using this code

    function topico_pre_get_posts( $query ){
    
        if( !is_admin() && is_tax('topico') && $query->is_main_query() && $query->is_tax() ){
    
        	$order = isset($_POST['order_custom']) ? $_POST['order_custom'] : 'DESC';
            
            $query->set('acfe_single_order', $order); 
    		$query->set('acfe_single_orderby', 'title');
    
            return $query;
        }
    }
    add_action( 'pre_get_posts', 'topico_pre_get_posts' );

    But it seems impossible to change acfe_single_order

    • This topic was modified 2 years, 9 months ago by gaspas.
Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Unfortunately the $query->set('acfe_single_orderby', 'title') doesn’t exists within the WP Query in the pre_get_posts hook (See documentation).

    The acfe_single_orderby is actually a property of the Taxonomy Object itself. What you’re looking for is $query->set('orderby', 'name').

    Also note that you have to set a priority higher that 10 in the pre_get_posts hook in order to override the settings in the ACFE Taxonomies UI. Usage example:

    add_action('pre_get_posts', 'my_pre_get_posts', 15);
    function my_pre_get_posts($query){
    
        if(!is_admin() && is_tax('topico') && $query->is_main_query() && $query->is_tax()){
            $query->set('orderby', 'name');
        }
    
    }
    

    Also note that there is nothing to return since it’s an action, not a filter.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘change acfe_single_order’ is closed to new replies.