In Wordpress, how do I set the default admin sort order for a custom post type to a custom column?

后端 未结 2 1099
逝去的感伤
逝去的感伤 2020-12-30 00:21

I\'ve set up a custom post type called clientarea, and set up several custom columns for it in the admin area - the custom columns are all custom meta fields, as you can see

2条回答
  •  隐瞒了意图╮
    2020-12-30 01:03

    Try change clientarea_default_order action & function for this:

    add_action('pre_get_posts', 'clientarea_default_order', 99);
    
    function clientarea_default_order($query) {
      if ($query->get('post_type') == 'clientarea') {
        if ($query->get('orderby') == '') {
            $query->set('orderby', 'extranet_sort_date');
            $query->set('meta_key', 'extranet_appointment_date');
        }
        if ($query->get('order') == '') {
            $query->set('order', 'DESC');
        }
      }
    }
    

提交回复
热议问题