Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pre_get_postsでアーカイブページのカテゴリ指定(除去)
/* アーカイブページのクエリ操作 */
function myPreGetPosts( $query ) {
if ( is_admin() || ! $query->is_main_query() ){
return;
}
if ( $query->is_archive() ) {
$query->set('cat', -9); //ID=9を除外 マイナスでなければカテゴリ指定
$query->set('posts_per_page', 30);
}
}
add_action('pre_get_posts','myPreGetPosts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.