Pagination in categories with permalink set to postname
-
Hi, I use this function to paginate posts within categories:
add_filter( 'pre_get_posts', 'number_of_posts' ); function number_of_posts( $wp_query = '' ) { remove_filter( 'pre_get_posts', 'number_of_posts' ); global $wp_query; $cat_obj = $wp_query->get_queried_object(); $category_id = $cat_obj->term_id; if ( is_category(3) ) { $wp_query->query_vars['posts_per_page'] = 2; } elseif( is_category(1)) { $wp_query->query_vars['posts_per_page'] = 1; } return $wp_query; }
It works very fine if permalinks are set on default. But, if I use %postname%, it doesn’t work, and the number of displayed posts is the same of the global $posts_per_page set in “Settings / Reading”…
Any idea?
Thanks in advance!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Pagination in categories with permalink set to postname’ is closed to new replies.