Skip to content

Instantly share code, notes, and snippets.

@JLeuze
Created June 22, 2012 16:15
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 JLeuze/2973780 to your computer and use it in GitHub Desktop.
Save JLeuze/2973780 to your computer and use it in GitHub Desktop.
Queries fix for Flexible theme
<?php
add_action( 'pre_get_posts', 'et_custom_posts_per_page' );
function et_custom_posts_per_page( $query ) {
global $shortname;
if ( is_admin() ) return $query;
if ( $query->is_main_query() && $query->is_category ) {
$query->set( 'posts_per_page', et_get_option( $shortname . '_catnum_posts' ) );
} elseif ( $query->is_main_query() && $query->is_tag ) {
$query->set( 'posts_per_page', et_get_option( $shortname . '_tagnum_posts' ) );
} elseif ( $query->is_main_query() && $query->is_search ) {
if ( isset($_GET['et_searchform_submit']) ) {
$postTypes = array();
if ( !isset($_GET['et-inc-posts']) && !isset($_GET['et-inc-pages']) ) $postTypes = array('post');
if ( isset($_GET['et-inc-pages']) ) $postTypes = array('page');
if ( isset($_GET['et-inc-posts']) ) $postTypes[] = 'post';
$query->set( 'post_type', $postTypes );
if ( isset( $_GET['et-month-choice'] ) && $_GET['et-month-choice'] != 'no-choice' ) {
$et_year = substr($_GET['et-month-choice'],0,4);
$et_month = substr($_GET['et-month-choice'], 4, strlen($_GET['et-month-choice'])-4);
$query->set( 'year', absint($et_year) );
$query->set( 'monthnum', absint($et_month) );
}
if ( isset( $_GET['et-cat'] ) && $_GET['et-cat'] != 0 )
$query->set( 'cat', absint($_GET['et-cat']) );
}
$query->set( 'posts_per_page', et_get_option( $shortname . '_searchnum_posts' ) );
} elseif ( $query->is_main_query() && $query->is_archive ) {
$query->set( 'posts_per_page', et_get_option( $shortname . '_archivenum_posts' ) );
}
return $query;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment