Last active
February 10, 2017 21:04
-
-
Save carasmo/b9f42f382ea28fc8a0d06af21c2ea6c7 to your computer and use it in GitHub Desktop.
Avoiding the 404 when pagination of a cpt or term of cpt does is under the posts per page settings in reading settings.
This file contains hidden or 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 | |
//don't add | |
// posts per page for CPT 'your-cpt' | |
function yourprefix_posts_per_page_in_portfolio_cpt( $query ) { | |
if ( ! is_admin() && is_post_type_archive( 'your-cpt' ) ) { | |
$query->set( 'posts_per_page', 2 ); | |
} | |
} | |
add_filter( 'parse_query', 'yourprefix_posts_per_page_in_portfolio_cpt' ); | |
// posts per page for term (your-term-slug) of CPT 'your-cpt' | |
function yourprefix_posts_per_page_in_term_of_portfolio_cpt( $query ) { | |
if ( ! is_admin() && term_exists( 'your-term-slug' ) && ! is_post_type_archive( 'your-cpt' ) ) { | |
$query->set( 'posts_per_page', 1 ); | |
} | |
} | |
add_filter( 'parse_query', 'yourprefix_posts_per_page_in_term_of_portfolio_cpt' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment