If you merely want to modify posts_per_page
for tag and category archive index pages, don’t use query_posts()
; instead, filter the $query
via pre_get_posts
:
function wpse87489_filter_pre_get_posts( $query ) {
if ( ( is_category() || is_tag() ) && $query->is_main_query ) {
$query->set( 'posts_per_page', '2' );
}
}
add_action( 'pre_get_posts', 'wpse87489_filter_pre_get_posts' );
Related Posts:
- Display one latest post from multiple categories
- Five posts from a category in footer
- Multiple Loops on category.php with pagination on last loop
- WordPress Numeric Pagination with Query String [duplicate]
- Get the number of posts from the current page results
- WP_Query not looking at child category
- Exclude category from loop not working
- 3 Columns, 3 Categories, One Archive, and Pagination
- Enter a variable in the ‘category_name’ parameter
- How to query post like normal search would do. within search.php page
- Query Posts Exclude Entire Category
- Blog post per page setting conflicting with custom WP_Query?
- Order by category titles
- Custom loops, sticky posts, and pagination nightmare
- pagination not working for category.php (custom post types in categories)
- Set colors depending on category
- Problem with different query loops (and “main loop”) on category template page!
- How to do paging in the loop?
- category__not_in and id values from variable
- Pagination for query_posts();
- More efficient way to list posts by category [duplicate]
- Show multiple categories in query using redux framework variable
- multiple values in an array for category__and does not work with WP_Query
- Paginate pages with dynamic query
- Posts of specific category on page and excluded from index.htm
- new WP_Query issues
- the_category() doesn’t working in wp_query loop
- Conditional category query breaking?
- Function the_posts_pagination() not compatible with WP_Query arguments
- Show the number of the post
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Pagination does not work with query_posts()
- Assign a class to first element in category in loop
- Loop within category’s posts
- Printing direct descendants of a category with WP_Query
- Custom Category Page Not Working [duplicate]
- Paginate WordPress Category Pages
- How do i add custom post types to this query?
- Using pagination with multiple loops causes it to break
- Showing one post from each category, paged?
- Pagination in category.php not functioning
- How can I implement pagination on custom category page?
- Show number of posts AND number on current page (cannot make it work)
- Pagination only showed when no category is set in wp_query
- How do I exclude a custom taxonomy from the post loop
- Some doubts about how the main query and the custom query works in this custom theme?
- Get the children of the parent category
- Get posts from sites in Multisite?
- Multiple WP_Query loops with Pagination
- How to check if I’m on the last page of posts?
- Display posts from the same category using next/previous post link
- How can I create a category landing page followed by pages of posts?
- WP_Query vs get_posts
- Get all categories and posts in those categories
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Should category.php and The Loop be used if the query needs to be customizable?
- Inject post (from specific category) between posts in Loop
- Pagination returns 404 after page 20
- Exclude the category from the WordPress loop
- Custom post type archive 404’s with paginate_links
- How do I get the category URL from get_the_category?
- Combine two taxonomies in a hierarchical tree
- Display all posts from specific categories on a page
- How to get posts from two categories with WP_Query?
- Group WP_Query by category
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- Order posts by ID in the given order
- Display all posts from all categories with pagination
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Exclude categories from search query
- get_field not displaying my custom field value
- How to exclude latest x posts from a paginated query?
- Default WP Gallery – show only galleries of a certain category
- WordPress Custom Query to show posts from last x years
- How can I reduce the number of database query calls for this custom homepage?
- Rearranging posts based on categories
- Build a content and excerpt grid loop with paging and options for # of posts
- Randomise results from a category page?
- Query Custom Meta Value with Increment
- Get page content by category or tag
- Using categories & “stickyness” together
- Display all posts in category, with specific tag posts at top
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Show div only if post is in specific category
- List posts by category exclude current post
- Pagination with 5 posts per page
- Show Previous/Next Posts navigation only inside the same category
- How to show a category post to a specific registered user
- Display list of Sub-Categories and the posts they contain, within one main Category
- Loop with Dynamic Categories
- Retrieving 3 latest post from each of 5 different custom post types
- How to order category.php loop by ‘meta_value’?
- Pagination/infinite scroll with WP_Query and multiple loops
- Excluding posts from a category but only if they’re not in multiple categories
- How can I create a loop to build slides based on multiple categories using Coda Slider
- What could be causing my wp_query pagination to break?
- Display only the latest post from multiple categories
- Custom query with category exclusion and post-meta “whitelist”
- Remove child products from woocommerce category page [closed]
- Get a list of commas separated categories inside a loop