我找不到任何结合$query->set(\'property\', \'value\')
使用数组的语法,假设这是正确的方法
在您的$args
数组,您定义了meta_query
和orderby
作为数组,它们各自是WP_Query
(或上述“属性”的值),因此在自定义函数中(set_post_order_in_admin()
), 仅使用$query->set( \'meta_query\', <array> )
和$query->set( \'orderby\', <array> )
像这样:
// In the set_post_order_in_admin function:
// Replace these lines:
$query->set( \'meta_key\', \'Order\' );
$query->set( \'orderby\', \'meta_value_num\' );
$query->set( \'order\', \'DESC\' );
// with the following:
$query->set( \'meta_query\', array(
\'relation\' => \'AND\',
\'resume_order\' => array(
\'key\' => \'Order\',
\'type\' => \'NUMERIC\'
),
\'resume_suborder\' => array(
\'key\' => \'Sub order\',
\'type\' => \'NUMERIC\'
),
) );
$query->set( \'orderby\', array(
// <orderby> => <order>
\'resume_order\' => \'DESC\',
\'resume_suborder\' => \'ASC\'
) );
或者你是说别的什么?
此外,仅当当前WP_Query
是WordPress的主要查询,以避免自定义筛选器与其他WP_Query
呼叫。所以你会这么做if ( is_admin() && $query->is_main_query() )
而不仅仅是if ( is_admin() )
.