Forked from yanknudtskov/change-posts-per-page-on-the-fly.php
Created
June 18, 2018 07:43
-
-
Save INDIAN2020/df6f284422acd4b4be1d2cb164bd8f7d to your computer and use it in GitHub Desktop.
Changing posts per page on the fly From http://wordpress.stackexchange.com/questions/30757/change-posts-per-page-count/30763#30763
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
| 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', 3 ); | |
| } | |
| elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) { | |
| $query->set( 'posts_per_page', 5 ); | |
| } | |
| // Etc.. | |
| return $query; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment