Created
September 12, 2011 21:53
-
-
Save billerickson/1212577 to your computer and use it in GitHub Desktop.
Change posts per page for 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
<?php | |
/** | |
* Change 'products' posts per page on archive | |
* This is the long version that explains everything | |
*/ | |
function be_modify_products_query_long ( $query ) { | |
// Check to make sure we're modifying the main query | |
global $wp_the_query; | |
if( $wp_the_query !== $query ) | |
return; | |
// Make sure we're not in the admin area | |
if( is_admin() ) | |
return; | |
// Make sure we are on the post type archive query | |
if( is_post_type_archive( 'products' ) ) { | |
$query->set( 'posts_per_page', '8'); | |
} | |
} | |
/** | |
* Change 'products' posts per page on archive | |
* This is the short version we actually use | |
*/ | |
function be_modify_products_query( $query ) { | |
global $wp_the_query; | |
if( $wp_the_query === $query && !is_admin() && is_post_type_archive( 'products' ) | |
$query->set( 'posts_per_page', '8' ); | |
} | |
add_action( 'pre_get_posts', 'be_modify_products_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment