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