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
- Why are the comments disabled by default on my custom_post_types?
- Linking Two Post Types
- How do I filter the excerpt metabox description in admin?
- Setting up custom post type archives in WP3.1? Any luck?
- Best Way to Create a List of Musician Gigs in WordPress
- Querying custom posts and regular posts
- Pagination not working with custom category template
- TV Show database – Best way for structuring it?
- Why is the »_builtin« parameter not advised in »register_post_type()« for custom post types?
- Using Offset in Custom Post Type Query
- Posts in Multiple Columns and Rows with one single loop
- Using Query Posts With Multiple Post Types And A Taxonomy
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- ‘category__and’ for custom taxonomy?
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- Sub-Sub-Blogs — creating and importing content into a custom sub-type
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Pagination problem
- Custom post type archive not regarding ‘posts_per_page’ => -1
- Show Two custom Post type and their posts on category page
- Custom post type and body_class: Remove “blog” class
- Custom post type, permalinks & pagination, going wrong
- Pagination for custom php code
- How to check post type (to include custom css)
- Custom taxonomy rewrite give pagination 404
- Next and Previous Posts of Same Parent
- delete_published_posts does not work
- Cannot save CPT meta box
- non-hierarchical post type with hierarchical url structure
- Next Post links not working in custom post type shortcode
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Custom WP_Query always respond with 200 status even when no entry
- Pagination 404 on Index with custom query
- List Categories (wp_terms) and count posts
- Not able to export large no. of posts in csv
- Get_the_terms restrict output
- How to insert data into meta box from another plugin?
- YOAST SEO won’t work on custom post type archive [closed]
- Break up posts per page in two sections
- List All Custom Post Types Posts in Nav Menu Dynamically
- post_content is stripping HTML when adding a new post? [closed]
- Dynamic category name in query post
- Custom Post Type Archive Pagination
- $wpdb is queried but results don’t show
- How to keep a record of changes to a custom field?
- How to create Custom image post?
- Custom post type pagination error
- Query for bbPress replies to current topic?
- WP query_posts group by meta field related
- Custom post type paging return home page
- custom post type and a “sticky” position taxonomy
- Pagination on custom post type without plugin
- Set a Default CPT taxonomy by taxonomy id
- Publish metabox postition?
- Need folder for CPT templates for eg: single-{post_type}.php
- Pagination for custom query returns 404
- WordPress deletes custom posts instead of trash them
- Pagination functions won’t work
- pagination for a custom query
- How to Fix Custom WordPress Loop with Pagination on Single Post View?
- Using $seed on a custom post type for randomly displayed posts
- Pagination in custom loop for custom post type throwing 404 error
- Collection of fields in a single post
- WordPress Load more posts by ajax not working
- pagination does not work with query_posts. Help! [duplicate]
- WordPress custom post type post and category links 404
- Pagination not working for archive
- How to add custom column to Custom post page list?
- Pagination not working
- CPT Archive Pagination – Page not found
- Assign a tag to custom post type using a query
- Two pagination in one page without AJAX