Skip to main content
added 11 characters in body
Source Link
WebElaine
  • 9.7k
  • 1
  • 16
  • 27

$screen may not be available yet when pre_get_posts fires. Try this instead:

public function my_post_type_default_sort( $query ){
    if(!isset($_GET['orderby']) && is_admin()) {
        $orderby = '0';
    }
    if($query->is_main_query() && is_admin() && is_singleis_post_type_archive('my_post_type') && $orderby=0) {
        $query->set('orderby','scr_date');
        $query->set('order', 'ASC');
    }
}

$screen may not be available yet when pre_get_posts fires. Try this instead:

public function my_post_type_default_sort( $query ){
    if(!isset($_GET['orderby']) && is_admin()) {
        $orderby = '0';
    }
    if($query->is_main_query() && is_admin() && is_single('my_post_type')) {
        $query->set('orderby','scr_date');
        $query->set('order', 'ASC');
    }
}

$screen may not be available yet when pre_get_posts fires. Try this instead:

public function my_post_type_default_sort( $query ){
    if(!isset($_GET['orderby']) && is_admin()) {
        $orderby = '0';
    }
    if($query->is_main_query() && is_admin() && is_post_type_archive('my_post_type') && $orderby=0) {
        $query->set('orderby','scr_date');
        $query->set('order', 'ASC');
    }
}
Source Link
WebElaine
  • 9.7k
  • 1
  • 16
  • 27

$screen may not be available yet when pre_get_posts fires. Try this instead:

public function my_post_type_default_sort( $query ){
    if(!isset($_GET['orderby']) && is_admin()) {
        $orderby = '0';
    }
    if($query->is_main_query() && is_admin() && is_single('my_post_type')) {
        $query->set('orderby','scr_date');
        $query->set('order', 'ASC');
    }
}