As in the comments, it’s not clear why you can’t use the options: dashboard -> settings -> reading -> Blog pages show at most [] posts
However, if it is necessary that this be done via altering the query (say to target only specific pages, or archives) then this should really be done on pre_get_post
:
For instance to change the post’s per page for any archive for a term in the ‘my-tax’ taxonomy:
add_action('pre_get_posts','wpse26898_change_per_post');
function wpse26898_change_per_post( $query ){
if( $query->is_main_query() && is_tax('my-tax') ){
$query->set('posts_per_page'=>2);
}
}
Related Posts:
- 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
- Custom posts per page does not work with pagination
- 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
- Querying posts only if the current page is not paged?
- query_posts pagination will always show identical content
- Can’t get pagination to work for sticky posts only
- Pagination linking to first page
- Modify main loop query for paged and meta key
- Post Filter clearing on pagination $_post
- get_next_posts_link() stops displaying at page 4
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Achieving pagination with `query_posts`
- posts_per_page no limit
- Alternative to query_posts for main loop? [duplicate]
- Query posts by custom taxonomy ID
- Query posts: how to exclude results if post is in multiple categories
- query_posts ->using meta_compare / where meta value is smaller or greater or equals
- Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
- WP 5.8 “Query Loop” block: where to place custom query?
- Best way to load page content in Fancybox popup?
- order post my meta value m/d/y format with year as included value
- _wp_page_template to dynamically use template
- Schedule Sticky Posts
- Total Count of Posts NOT in Selected Categories?
- Problem with single-page for my custom post
- How to modify the query to exclude posts by slug?
- How to make the list of post and load on same page with sub-pages [closed]
- How to get 4 Posts after the 5 most recent ones
- post_status => publish not working
- How do I make archives.php for one category only?
- making random query button using $_GET
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- How do I change the default sort order of a custom column on the posts page?
- how to exclude “featured” posts from the main loop?
- Five posts from a category in footer
- Order posts by condition
- Co-authors plus problems with query_post
- Search breaks when querying main loop for category
- Authors List page – How to include only those with wp_user_level as Author
- Blog post per page setting conflicting with custom WP_Query?
- Query posts by meta_key whose value is an array
- Show Blogroll of another WordPress site
- Why this code causes infinite loop?
- Each post is showing twice in my custom query…?
- query_posts() – problem with “s” parameter
- Pagination on category.php and tag.php not working
- Page title in post query
- Question about querying posts
- Pagination for query_posts();
- Breadcrumbs stop working on a specific template file
- Does WordPress run a post query when a page is invoked?
- Multiple posts/pages in one page?
- Order for custom field after the loop
- Custom post query error
- Multiple instances of query_posts
- Different layout based on post amount?
- Trouble Making WP_Query paged
- If Query Post Returns 1 Post
- Calling Posts from Specified Cat
- Keeping get_posts’ offset and is_paged() synchronized
- odd behaviours from template tags
- How do I add a timezone offset to this query?
- query_posts thumbnail condition
- How to get any type posts include attachments by ids?
- Create a Loop with Posts Ordered by Most Recent Comments
- Tax query get first product with attribute value in pre_get_posts
- Specifying image size used in template the_content
- allow user to edit posts made by others users based on the user role
- Pagination does not work with query_posts()
- Pagination not working on my archive page for a custom post type
- No duplicate tags by category
- Order posts by ACF checkbox
- Post per page not working
- Show previous month’s posts
- query_posts result differs from wp_query request result
- If meta_key has value = 6 | Change the wp_posts.post_date to current date
- How to inject a post within a loop
- Adding Category Argument into an Array for WordPress Query
- orderby not working for query_posts using array of IDs
- Collect posts from last 48 hours
- How to go to tag archives using a form
- Why doesn’t this page query work?
- Showing one post from each category, paged?
- query posts returns 10 records
- Resetting a Query using wp_reset_query() or wp_reset_postdata() does not work
- Sort posts with multiple meta_keys
- How to get custom post type posts with certain multiple tags names and category id?
- Create “archives by year and week” by category template
- query_posts different amount of posts per page [duplicate]
- Show number of posts AND number on current page (cannot make it work)
- /page/2/ redirect to 404