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
- Get the children of the parent category
- Multiple WP_Query loops with Pagination
- How do I get the category URL from get_the_category?
- Display all posts from all categories with pagination
- Default WP Gallery – show only galleries of a certain category
- Display all posts in category, with specific tag posts at top
- How to order category.php loop by ‘meta_value’?
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Select category in custom query
- Custom category template pagination problem
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Converting multiple loops into one single loop with pagination
- Custom WP_Query for current category (in category.php)?
- How would I get 1 latest post from a query for 5 posts?
- Why would in_category only return one post in a specific category?
- getting content from main domain to sub-domain using category and WP_Query
- How to show subcategories using loop?
- WordPress pagination showing same posts on each page
- Checking for two categories in query_posts
- Restoring default article pagination on archives – Removing custom limits
- Why category.php throw 404 in wordpress while calling paginate_links()?
- Check if loop has any categories?
- How to get latest posts from each category in regular order
- Category archives with monthly pagination
- Pagination for ajax category filter
- How do I query_posts in cat=1 AND not in cat=2
- Display single category name in woocommerce loop
- Show Posts from Single Category Not Working
- query_posts not reading correct categories
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- WP_Query: Show 10 posts in date order, first three random
- Adding a block with query in homepage
- I need to exclude from a query a category and a few custom taxonomies
- WP_Query of Category Not Showing First Post
- List post only under the category, exclude child category content
- Custom Post Type Query W/Category Dropdown
- How to get posts using category slug in ClassiPress?
- query_post problem
- Filter products on category AND tag
- Problem with pagination block in Gutenberg
- How do I stop the same post showing multiple times in a archive?
- query_posts() doesn’t seem to be called in my page
- Removin /page/2 from pagination
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Display one post on category.php: Wrong featured image
- Display related posts with same category or same tag return blank
- Category foreach Paging
- date.php shows all posts. how to fix it?
- How to inject a post within a loop
- wordpress category.php query for featured news item, broken pagination and repeating posts
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- Query pages by category
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- How to exclude certain portfolios from a loop
- query_posts different amount of posts per page [duplicate]