Skip to content

Instantly share code, notes, and snippets.

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 chibani/1554288 to your computer and use it in GitHub Desktop.
Save chibani/1554288 to your computer and use it in GitHub Desktop.
WordPress : Hack to give a custom posts_per_page value for a custom post type
//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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment