1
我有什麼顯示每個自定義後類型最新的帖子與pre_get_posts
在我的頭版我已成功地改變了頭版的主要查詢,以顯示我的自定義文章類型與「pre_get_posts 「是這樣的:
function custom_post_types_in_home_loop($query) {
if (! is_admin() && is_home() && $query->is_main_query()) {
$query->set('post_type', array('member', 'press', 'calendar_event'));
}
return $query;
}
add_filter('pre_get_posts', 'custom_post_types_in_home_loop');
我想要什麼
問題是,有些帖子類型比其他帖子有更多的帖子,所以我想每個帖子類型只顯示3帖子,以獲得循環中的一些變化。
我已經試過
與this和this答案IVE一些幫助成功地做到這一點,但什麼也沒有發生,我究竟做錯了什麼?
function custom_post_types_in_home_loop($query) {
if (! is_admin() && is_home() && $query->is_main_query()) {
$query->set('post_type', array('member', 'press', 'calendar_event'));
if ($query->get('post_type') == 'member') {
$query->set('posts_per_page', 3);
}
/* And the same 'if' statement for 'press' and 'calendar_event' */
}
return $query;
}
add_filter('pre_get_posts', 'custom_post_types_in_home_loop');
感謝您的回答,現在我看到我的錯誤與數組/字符串比較,並且顯然不工作..我設法解決問題與另一種方法來幫助這個答案http://wordpress.stackexchange。 COM/A/71582 – Rocaboca