Last active
August 29, 2015 14:17
-
-
Save jnicol/67f3d17aae7dd301fb35 to your computer and use it in GitHub Desktop.
WordPress: Customize the number of posts displayed per Custom Post Type
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
/** | |
* Customize number of posts displayed per Custom Post Type | |
* | |
* @see https://mondaybynoon.com/wordpress-posts-per-page-per-custom-post-type/ | |
*/ | |
function custom_posts_per_page($query) { | |
if(!is_admin()) { | |
switch ($query->query_vars['post_type']) { | |
case 'name_of_cpt1': | |
$query->query_vars['posts_per_page'] = -1; | |
break; | |
case 'name_of_cpt2': | |
$query->query_vars['posts_per_page'] = 20; | |
break; | |
default: | |
break; | |
} | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts', 'custom_posts_per_page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment