我已经搜索过了,但没有找到问题的答案。我有一个用于订购的元键帖子。我想按此值订购post。如果它们有相同的值,我希望它们按日期排序。
我猜这就是要使用的查询:
new WP_Query( array(
\'post_type\' => array (\'post\', \'aggregato\'),
\'cat\' => \'-1\',
\'posts_per_page\' => 12,
\'orderby\' => \'meta_value_num date\',
\'order\' => DESC,
\'meta_key\' => \'mb_home\',
\'meta_query\' => array(
array(
\'key\' => \'mb_home\',
\'value\' => 0,
\'compare\' => \'!=\',
)
)
));
(the
\'cat\' => \'-1\'
只是排除特定类别的另一项检查)
现在,此查询返回“mb\\u home”值不同于0的帖子。它按这个值排序。但完全忽略了“日期”。如果我有两篇具有相同mb\\U home值和不同日期的帖子,它只会按照预期的日期ASC而不是日期DESC。
有什么指示吗?我做错了什么?
编辑:这是转储。
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE 1=1 AND ( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (1) ) ) AND wp_posts.post_type IN (\'post\', \'aggregato\') AND (wp_posts.post_status = \'publish\' OR wp_posts.post_author = 1 AND wp_posts.post_status = \'private\') AND (wp_postmeta.meta_key = \'mb_home\' AND (mt1.meta_key = \'mb_home\' AND CAST(mt1.meta_value AS CHAR) > \'0\') ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0,wp_posts.post_date DESC LIMIT 0, 12