Skip to content

Instantly share code, notes, and snippets.

@Hube2
Last active August 29, 2015 14:06
Show Gist options
  • Save Hube2/5eb1bbb01d44f86cd8a5 to your computer and use it in GitHub Desktop.
Save Hube2/5eb1bbb01d44f86cd8a5 to your computer and use it in GitHub Desktop.
Using pre_get_posts
<?php
// example, set posts_per_page on CTP "book"
function books_pre_get_posts($query=false) {
if (is_admin() ||
!$query ||
!is_a($query, 'WP_Query') ||
!$query->is_main_query()) {
return;
}
if (isset($query->query_vars['post_type']) &&
$query->query_vars['post_type'] == 'books') {
$query->set('posts_per_page', 2);
$query->set('order', 'DESC');
}
}
add_action('pre_get_posts', 'books_pre_get_posts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment