我有一个查询,它提供了按类别排序的自定义帖子类型的帖子和一个自定义字段,其中有一个数字表示帖子的投票数量。问题是,如果2个帖子有3个投票,有时当你刷新时,它会改变他们的位置。这是代码:
$args = array(
'numberposts' => 10,
'post_type' => 'nominees',
'meta_query' => array(
array(
'key' => 'category',
'value' => get_the_ID(),
'compare' => '=',
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => 'count_nominees'
);
我尝试在类别元查询中添加订单,但没有任何更改,如果帖子的投票数相同,我在刷新时有时会得到不同的结果。按ID或其他方式添加第二个订单的正确方法是什么?
感谢。
答案 0 :(得分:1)
正如评论中所提到的,我认为this might help,但您可以将其扩展为在您的用例的搜索查询中更具体一些。
$args = array(
'numberposts' => 10,
'post_type' => 'nominees',
'meta_query' => array(
array(
'key' => 'category',
'value' => get_the_ID(),
'compare' => '='
)
),
'meta_key' => 'count_nominees',
'orderby' => array(
'count_nominees' => 'DESC',
'ID' => 'DESC'
)
);
10
帖子类型中的帖子应该 nominees
,只有当他们属于xyz
类别时,并count_nominees
发布元count_nominees
,然后按descending
顺序排序post ID
,然后按descending
顺序排列##Force SSL
#Normal way (in case you need to deploy to NON-heroku)
RewriteCond %{HTTPS} !=on
#Heroku way
RewriteCond %{HTTP:X-Forwarded-Proto} !https
#If neither above conditions are met, redirect to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
。
您可以使用WordPress codex上的WP_Query
文档,了解有关使用后元数据的复杂查询的更多信息。