WordPress : Hack to give a custom posts_per_page value for a custom post type

  • Download Gist
WP : custom posts_per_page for custom post type
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//This code should be added in the plugin that manages the custom post type or in the functions.php of you theme
 
add_filter('request', 'hack_pagination');//Register the filter
 
/**
* Hack to give a custom posts_per_page value for a custom post type
* @param string $query_string automatically given by the filter
*/
function hack_pagination($query_string){
if($query_string['post_type']=='MY_CUSTOM_POST_TYPE' && !is_single() && !is_admin()) {
$query_string['posts_per_page'] = 2;//Number of posts I want in archive
}
return $query_string;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.