Skip to content

Instantly share code, notes, and snippets.

@chocotaro chocotaro/change_posts_per_page.php Secret
Last active Aug 12, 2016

Embed
What would you like to do?
pre_get_postsの使い方
function change_posts_per_page($query){
// 管理画面またはメインクエリでない場合は何もせず終了
if(is_admin() || ! $query->is_main_query()){
return;
}
//home.phpまたはアーカイブページの場合は10件表示、カテゴリID=5の記事は除外する
if($query->is_home() || $query->is_archive() ){
$query->set('posts_per_page', '10');
$query->set( 'cat', '-5'); // カテゴリーID5の記事を除く
return;
}
}
add_action('pre_get_posts', 'change_posts_per_page');
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.