Last active
July 16, 2020 05:42
-
-
Save chocotaro/219e36367a52f98f0133ec5f54b56b48 to your computer and use it in GitHub Desktop.
pre_get_postsでアーカイブページのカテゴリ指定(除去)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* アーカイブページのクエリ操作 */ | |
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