我需要完成以下工作:
按自定义字段“pin\\u to\\u top”按DESC顺序对CPT tribe\\u事件进行排序;未来的任何帖子
按ASC顺序对剩余帖子进行排序我的目标是在结果顶部保留任何“pin_to_top”=1的帖子,然后按事件日期按ASC顺序显示剩余结果。
我的问题是:
$data7 = array (
\'post_status\' => \'publish\',
// create array of arrays
\'meta_query\' => array(
// pin to top array
array(
\'meta_key\' => \'pin_to_top\',
\'meta_type\' => \'NUMERIC\',
\'meta_value_num\' => \'1\',
\'compare\' => \'=\'
),
// event start date array
array(
\'meta_key\' => \'_EventStartDate\',
\'meta_type\' => \'DATETIME\',
\'meta_value\' => \'$today\',
\'compare\' => \'>=\'
),
),
// custom post type
\'post_type\' =>
array (
\'tribe_events\' => \'tribe_events\'
),
// categories of custom post type
\'tribe_events_cat\' => \'events\',
// sorting
\'orderby\' => array(
\'pin_to_top\' => \'DESC\',
\'_EventStartDate\' => \'ASC\'
),
);
我愿意接受建议,请记住我只是刚刚开始使用WP Dev.TIA
SO网友:helle
几天前我也有过类似的经历
//.....
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'pin_clause\' = array(
\'meta_key\' => \'pin_to_top\',
\'meta_type\' => \'NUMERIC\',
\'meta_value_num\' => \'1\',
\'compare\' => \'=\'
)
),
array(
\'date_clause\' => array(
\'meta_key\' => \'_EventStartDate\',
\'meta_type\' => \'DATETIME\',
\'meta_value\' => \'$today\',
\'compare\' => \'>=\'
)
)
),
\'orderby\' => array(
\'pin_clause\' => \'DESC\',
\'date_clause\' => \'ASC\'
)
//....
我不知道你的名字是不是对了,但我想这会有助于理解这个把戏。