0
此代碼位於我的functions.php中。爲什麼WordPress不會使用此代碼顯示一類帖子?
我可以從首頁排除類別50的帖子,但完全相同的代碼不會使相反的情況發生在不同的頁面上。
有在類別的職位,我可以從/分類/蛞蝓/
我想設置的變量不被置見。我已與print_r
檢查。不過,該頁面沒有顯示任何帖子。
我不明白。
function exclude_category($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('cat', '-50'); // This part works
} else if ($query->is_page($pagename = 'santa-vs-krampus') && $query->is_main_query()) {
$query->set('category__in', '50'); // we get this far, it sets the variable, but doesn't show the posts.
/* print "<!-- Well, we got this far.";
print_r ($query);
print "-->"; */
}
}
add_action('pre_get_posts', 'exclude_category');