这应该很简单,但我无法找到一个正确语法的好例子。
我想按指定的meta\\u键和两个meta\\u查询排序。问题是query\\u帖子似乎不喜欢有两个带有meta\\u键的meta\\u查询。如果我取出一个meta\\u查询,代码就会工作,或者如果我删除meta\\u键并将orderby更改为title,而不使用meta\\u查询,代码也会工作。
有没有办法通过两个meta\\u查询按meta\\u键排序?
$args2 = array(
\'meta_key\' => \'_count-views_all\',
//\'meta_value\' => $id,
\'orderby\' => \'meta_value_num\',
\'order\' => $sortOrder,
\'posts_per_page\' => 9,
\'paged\' => $paged,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'contributorid1\',
\'value\' => $id,
\'compare\' => \'=\'
),
array(
\'key\' => \'contributorid2\',
\'value\' => $id,
\'compare\' => \'=\'
)
)
);
$posts = query_posts($args2);
}
SO网友:Pontus Abrahamsson
您可以使用3.1版以来的WP\\U查询和meta_query.
$args = array(
\'meta_key\' => \'_count-views_all\',
\'orderby\' => \'meta_value_num\',
\'order\' => $sortOrder,
\'posts_per_page\' => 9,
\'paged\' => $paged,
\'meta_query\' => array(
\'relation\' => \'OR\'
array(
\'key\' => \'contributorid1\',
\'value\' => $id,
\'compare\' => \'=\'
),
array(
\'key\' => \'contributorid2\',
\'value\' => $id,
\'compare\' => \'=\'
)
)
);
$query = new WP_Query( $args );