Last active
August 29, 2015 14:06
-
-
Save Hube2/5eb1bbb01d44f86cd8a5 to your computer and use it in GitHub Desktop.
Using pre_get_posts
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 | |
// 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