Enter your keyword

Blog

Post Per Page on Search and Category Page

add_action( 'pre_get_posts',  'set_posts_per_page'  );
function set_posts_per_page( $query ) {
    global $wp_the_query;
    if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
    	$query->set( 'posts_per_page', 10 );
    }
    elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_category() ) ) {
    	$query->set( 'posts_per_page', 10 );
    }
    return $query;
} 
 

No Comments

Add your review

Your email address will not be published.

* Feilds are Required.