0
我试图通过邮政类型优先搜索结果,使用pre_get_posts
钩 - track
帖子类型结果administration
帖子类型结果。 我不确定是否可以用$query->set('orderby', 'type')
完成。在WP_Query中使用相同的参数会有效,但我想避免这种情况。
这是全功能:
function tcb_pre_get_posts($query) {
if (is_admin() || ! $query->is_main_query())
return;
if (is_search()) {
$query->set('post_type', array('track', 'administration') );
$query->set('posts_per_page', 15);
$query->set('orderby', 'type');
// orderby 'post_type' did not work as well
}
}
add_action('pre_get_posts', 'tcb_pre_get_posts', 1);
Altough track
是post_type
阵列中administration
之前写的,在结果我看到administration
track
之前。
检查此链接https://开头的WordPress .stackexchange.com/questions/91890/add-multiple-order-with-pre-get-posts – vel
你的代码到底有什么问题?它看起来像是在做你想要的东西?你能描述一下你的期望吗? – Und3rTow
Und3rTow,谢谢你的评论。刚刚编辑了这个问题。 – yuvalsab