Support

Account

Home Forums Add-ons Repeater Field pre_get_post and nested while loop Reply To: pre_get_post and nested while loop

  • Thanks John. That’s not it (its actually a global that Learndash LMS creates)

    Even when I use

    add_action( 'pre_get_posts', 'my_change_sort_order'); 
        function my_change_sort_order($query){
            if(is_post_type_archive( 'sfwd-courses' )):
               $query->set('orderby', 'meta_value'); 
    		   $query->set('meta_key', 'expiry_date');   
    		   $query->set('order', 'DESC'); 
            endif;    
        };
    

    and I I check the output of archive-sfwd-courses.php, it does sort correctly (in this case according to descending expiry_date field) but it no longer displays the field presenter_info (the one in the nested while loop.)

    All the fields show correctly when I do not use the pre_get_posts function.