Use a pre_get_posts
action in your functions.php
with conditional tags, and remove the call to query_posts
:
function wpa62751_pre_get_posts( $query ) {
if ( is_category( 'my-category' ) && is_main_query() )
$query->set( 'posts_per_page', 4 );
}
add_action( 'pre_get_posts', 'wpa62751_pre_get_posts' );
Related Posts:
- Querying posts only if the current page is not paged?
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- Get the number of posts from the current page results
- Pagination on archive.php page
- Having trouble generating pagination links on custom query
- query_posts and pagination, still stuck after much research
- how could I get the pagination as I want to when query posts using get_posts function
- pagination in author.php template returns 404 error
- How do i paginate query_posts with numeric pagination?
- Pagination on custom query
- WordPress pagination showing same posts on each page
- WordPress pagination with get_posts?
- Using ajax with paging and a custom sub-query
- Custom loops, sticky posts, and pagination nightmare
- query_posts pagination will always show identical content
- Can’t get pagination to work for sticky posts only
- How do I use pagination in WordPress?
- Pagination, query more pages at once
- Pagination linking to first page
- filter posts by meta key with pagination
- Modify main loop query for paged and meta key
- Post Filter clearing on pagination $_post
- get_next_posts_link() stops displaying at page 4
- send user to first page of results when reposting to page?
- Achieving pagination with `query_posts`
- Using WP_Query to Query Multiple Categories with Limited Posts Per Category?
- Is there a way to exclude the content from the post variable to save on RAM usage?
- What is the difference between $paged and $page?
- Display/query post formats
- How to query post by user role?
- Ensuring sticky posts are retrieved first (without using two queries)?
- Determine if more posts are available than was asked for in `query_posts()`?
- query_posts() in function makes global $wp_query out of sync?
- Limiting query_posts to 1, regardless of sticky post?
- WordPress Custom Query
- How should I intercept the main query and inject custom join / order by / group by criteria
- advice on creating a ‘related posts’ query like the one used on stackexchange
- Using dynamic conditions in ‘posts_where’ filter
- Help altering a query to exclude all but standard post format
- How to limit search to first letter of title?
- Post Title displaying but not in the wrapped HTML I need
- get_post_meta causes database queries
- How to ensure that is_search() return false after query_posts
- Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
- Query 1 taxonomy term, exclude another
- Ordering terms before displaying posts
- What is the difference between “manage_{$post_type}_posts_columns” and “manage_edit-{$post_type}_columns”?
- Sort Posts by Multiple Meta Values [duplicate]
- Querying posts with meta value that begins with a certain pattern
- Adding Variables to post query
- Unable To Get Published posts using query_posts
- ACF Custom Field WP_Query, but need to get all posts, if field doesn’t exist
- making random query button using $_GET
- query_posts for child pages
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- orderby:date not working
- Placing post data (title, date, and excerpt) nested in static content
- paged > max_num_pages won’t throw 404
- Single meta key with multiple meta value in like comparison
- Authors List page – How to include only those with wp_user_level as Author
- list child page items (1 level with meta keys)
- Blog post per page setting conflicting with custom WP_Query?
- Sorting a query Field by date
- Show Blogroll of another WordPress site
- Trying to package posts for republishing by partner offsite
- Why this code causes infinite loop?
- Each post is showing twice in my custom query…?
- number of posts per page + random + exclude categories
- How to Query Post
- Custom WP_Query always respond with 200 status even when no entry
- query_post and wpdb returning different results
- Exclude current sticky post
- Page title in post query
- Question about querying posts
- WordPress Custom Query to get Most Commented Posts in the Past 7 Days
- WordPress query reverse order
- How to reverse post navigation at bottom of post
- Restrict query_posts by Date?
- How to solve this without flushing the rewrite rules for each post query the visitor triggers?
- Sort post by custom field numeric value
- Notting but the latest post content keeps on being loaded
- query_posts doesnt show pages with given ID when post_type => page
- Having an issue doing a WP_Query with post_content and category__and
- How to put posts in pages using query posts
- Query add html after set amount of posts?
- Custom loop off by one post
- How to setup blog page to render blog posts minus afew categories
- How to get max value of filtered query post
- Ordering of posts, 2020 Year showing as next event when should be last
- Pagination doesn’t work in query post in tag template
- Pagination diplays always 2 pages
- How to display most popular post by views count in WordPress?
- Custom pagination generates title 404
- Query counting excluded category on paged loop
- pagination does not work with query_posts. Help! [duplicate]
- query multiple posts by id using a string parameter, not array()
- query_posts – slightly more advanced query
- Query posts in a category and include only one post per author?
- paged query leads to 404? [duplicate]