管理员列无法正确排序-Orderby

时间:2019-01-27 06:21:18

标签: php wordpress sql-order-by

我在wordpress插件中具有功能,该功能可以查询Organzier是否为“ Premium”。我添加一个可排序的管理列。但这似乎工作不正确。只有一个管风琴弄错了。参见屏幕截图:[1]:http://prntscr.com/mcq351

add_filter('manage_tribe_organizer_posts_columns', 
'set_custom_edit_tribe_organizer_columns');

function set_custom_edit_tribe_organizer_columns($columns) {

$columns['premium_organizer'] = __('Premium Veranstalter', 
'your_text_domain');

return $columns;
}

add_action('manage_tribe_organizer_posts_custom_column', 
'custom_tribe_organizer_column', 10, 2);

function custom_tribe_organizer_column($column, $post_id) {
switch ($column) {

    case 'premium_organizer' :
$premium = CFS()->get("premium", tribe_get_organizer_ids($post_id) [0]);


        if ($premium)
            echo 'Ja';
        else
            _e('Nein', 'your_text_domain');
        break;
   }
}

add_filter('manage_edit-tribe_organizer_sortable_columns', 
'tribe_organizer_premium_organizer_column');

function tribe_organizer_premium_organizer_column($columns) {
 $columns['premium_organizer'] = 'premium_organizer';

return $columns;
}

add_action('pre_get_posts', 'tribe_organizer_premium_organizer_orderby');

function tribe_organizer_premium_organizer_orderby($query) {
if (!is_admin())
    return;

$orderby = $query->get('orderby');

if ('premium_organizer' == $orderby) {
    ///$premium = CFS()->get("premium", tribe_get_organizer_ids($post_id) 
[0]);
    $query->set('meta_key', 'premium');
    $query->set('orderby', 'meta_value_num');
  }
}

0 个答案:

没有答案