Skip to content

Instantly share code, notes, and snippets.

@mt8 mt8/functions.php
Last active Jul 20, 2016

Embed
What would you like to do?
[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
You can’t perform that action at this time.