Skip to content

Instantly share code, notes, and snippets.

@chocotaro
Last active July 16, 2020 05:42
Show Gist options
  • Save chocotaro/219e36367a52f98f0133ec5f54b56b48 to your computer and use it in GitHub Desktop.
Save chocotaro/219e36367a52f98f0133ec5f54b56b48 to your computer and use it in GitHub Desktop.
pre_get_postsでアーカイブページのカテゴリ指定(除去)
/* アーカイブページのクエリ操作 */
function myPreGetPosts( $query ) {
if ( is_admin() || ! $query->is_main_query() ){
return;
}
if ( $query->is_archive() ) { //月別、年別、日別、時間別アーカイブの場合はis_date()
$query->set('cat', '-1, -2, -3'); //IDを除外 複数はカンマで区切る マイナスでなければカテゴリ指定
$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