Last active
July 20, 2016 06:55
-
-
Save mt8/bc17028cf2fa48ac8981930b706ba057 to your computer and use it in GitHub Desktop.
[WordPress] カスタム投稿タイプのアーカイブ件数を変更する
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
<?php | |
function set_cpt_per_page( $query ) { | |
$cpt = 'news'; | |
$per_page = 10; | |
if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( $cpt ) ) { | |
$query->set( 'posts_per_page', $per_page ); | |
} | |
} | |
add_action( 'pre_get_posts', 'set_cpt_per_page' ); | |
function set_cpt_per_page_with_tax( $query ) { | |
$cpt = 'news'; | |
$tax = 'topic'; | |
$per_page = 10; | |
if ( ! is_admin() && $query->is_main_query() && ( is_post_type_archive( $cpt ) || is_tax( $tax ) ) ) { | |
$query->set( 'posts_per_page', $per_page ); | |
} | |
} | |
add_action( 'pre_get_posts', 'set_cpt_per_page_with_tax' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment