Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 12, 2011 21:53
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 billerickson/1212577 to your computer and use it in GitHub Desktop.
Save billerickson/1212577 to your computer and use it in GitHub Desktop.
Change posts per page for post type
<?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