Here’s what I usually use the pre_get_posts
action to change a single query value for a taxonomy or category page:
/**
* Control the number of search results
*/
function custom_posts_per_page( $query ) {
if ( $query->is_tax('mytaxonomy') || $query->is_category('mycategory') ) {
set_query_var('posts_per_page', 9);
}
}
add_action( 'pre_get_posts', 'custom_posts_per_page' );
Related Posts:
- what is the correct way to compare dates in a WP query_posts meta_query
- Custom post type archive 404’s with paginate_links
- Query posts by custom post type and custom taxonomy
- Query post types with multiple keys
- posts_nav_link on single post template
- Get all posts WHERE custom_field is LIKE value
- How to insert content from another Custom Post type into Post?
- CPT: if more than X images are in post, use pagination
- Display only one post each WEEK
- Conditional Query of Custom Post Type and custom taxonomy
- will post_id ever change? Can I safely use post_id for custom queries?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- How do I move/order posts with a tag to the end?
- How to handle paged param in post and custom-post-type?
- Category with post type pagination returns 404
- pagination not working for category.php (custom post types in categories)
- Number of posts in the archive
- attach CPT data to a taxonomy
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Sticky posts limit query and pagination for a custom post type
- custom post type and user post count shortcode
- Use WP pagination functions on a custom page template
- Custom Pagination based on Custom Post Type
- Custom post type blog pagination conflict
- What’s the best way to show custom post types? With page template it’s not perfect!
- How to apply order on custom taxonomy and custom meta key on custom post type
- send user to first page of results when reposting to page?
- Inserting two categories
- Page vs Custom Post Types Differences/Issues
- How to check post type (to include custom css)
- How to display all posts from standard posts to custom post types in a loop with pagination?
- How to customize a permalink (URL) structure?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Plugin: register custom post types, child ready and performance best practices
- List children on child post
- How to Mass Delete Images from Media Library
- Previous/Next Link by Meta Value in CPT
- Custom post type not displaying all entries
- How to query_post custom posts within default taxonomy?
- Custom post type (with parent-child relationship) singular page with pagination
- Pagination for Custom Taxonomy Page [duplicate]
- Get posts between custom dates
- Pagination on with query_posts in custom post type template
- child of post type (custom)
- Permalink structure by Post Meta value
- Page template with different page and post content
- How to use custom taxonomies to reference complex relationships?
- How to integrate video slide using custom post types?
- Order query using custom meta data
- Query Custom posts of same taxonomy as the post itself
- Get latest 3 posts from multiple CPT in one query
- get custom post type
- Pagination of Custom Post Types not Changing Posts
- A question on creating filters for custom posts using taxonomy
- List custom taxonomy specific to one custom post type
- Define new user capability for custom post types?
- How to allow visitors to enter custom post type?
- Show a Category X’s custom post type on Category X archive page?
- Paging doesn’t work?
- Is it possible to create relational metabox values in a custom post?
- Meta query for custom post type ignored in main query
- Help with Elementor Pagination CPT archive 404 problem
- 2 Templates 1 custom post type according url
- changing meta value and meta key of price field
- WordPress sort search results by custom order
- Custom taxonomy rewrite give pagination 404
- Next and Previous Posts of Same Parent
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Hide parent categories when clicked, and show it’s childs
- Custom Path/Folder behind a custom post type
- Time based access control of custom post types – what is good approach?
- Show titles, date of all posts on single category page
- Add Pagination on Custom Post Type Archive
- Woocommerce search pagination not working
- Custom template Page 2 not working
- delete_published_posts does not work
- How to start a new post with custom Taxonomies already set?
- WooCommerce sort products by the actual product width(not the shipping width)
- Create a custom php page and load it at a specific slug
- Structure of data : CPT + terms
- How do you paginate a query grouped by month?
- Default text in a specific post type, but not visible?
- Update postmeta Parent when post_status child change
- Polylang non-default language ignores tags in WP_Query
- List all posts in a custom post type with pagination (the correct way)
- How to edit this code to get the categories in achieve page?
- WP_Query custom post type query not showing the exact post type
- custom post type pagination error 404
- How To Show All Custom Post Types In A Category Instead Of Pagination?
- Pagination issue on category.php using custom post type query
- Shortcode to display Staff post type based on Location post type and Specialty post type
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to remove post listing page for a custom post type
- How to include term custom meta into the custom taxonomy term permalink structure
- Custom Post Type Pagination Paginates Only in URL Structure
- Is it possible to to use custom post type types on a page with the same slug somehow?
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- WordPress custom post query with pagination
- A form that can save/edit after first input
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?