Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mt8
Last active July 20, 2016 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mt8/bc17028cf2fa48ac8981930b706ba057 to your computer and use it in GitHub Desktop.
Save mt8/bc17028cf2fa48ac8981930b706ba057 to your computer and use it in GitHub Desktop.
[WordPress] カスタム投稿タイプのアーカイブ件数を変更する
<?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