You can use pre_get_posts
and is_category
conditional tags to set posts_per_page
to 10 for category pages.
Here is a working exacmple
function wpse_posts_cat_pages( $query ) {
if ( $query->is_category() && $query->is_main_query() ) {
$query->set( 'posts_per_page', '10' );
}
}
add_action( 'pre_get_posts', 'wpse_posts_cat_pages' );
What this code do:
- Check if it is the main query
$query->is_main_query()
and if the page is a category (category.php) page$query->is_category()
, and if both of these are valid, the amount of posts are limited to 10, no matter what is set in the back end
Related Posts:
- Can I set a default featured image for a category?
- Could not insert term into the database
- Weird behaviour when adding terms/term_taxonomies programmatically
- How can I get category ID by category name?
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Only show category to certain user levels without plugin
- Custom Query to search through categories
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Get sticky post from category?
- Remove word “Category” from WooCommerce product page [closed]
- Output link to category from WP_Query loop of woocommerce products
- Display name of the last child category
- If in category to be inside of a function
- How to exclude posts from a category when using this particular format
- Viewing category pages without the word ‘category’ in URL
- Different excerpt styles per category, but chronological
- Show only one category
- Pagination Not Working on Category.php page
- How to view WordPress’ default category IDs?
- Filter Home Page Posts in Buddypress [closed]
- Broken category pagination
- Color different for the current category
- how to change template?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Product Category WooCommerce
- Hard coded main navigation
- one category template for multiple categories
- Display posts separated by Category in Author’s page
- How can I define a custom archive for childs of a specific category?
- Category shows only top level child categories
- The arrangement of categories always change while posting article
- Page display certain Category Posts
- REST API: Display Category names in JSON?
- List posts in alphabetical order
- Where is the category of a post stored?
- Categories list loop – add separator every 3 categories [closed]
- Add image to each podcast series (or category) in headless WordPress instance [closed]
- wp_list_pages() exclude category
- How to define multi categories posts number
- Get the ID of 10 Latest Pages stored in a WordPress Category
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- how to separate categories in loop.php?
- How can i remove the posts category class names from body_class
- Different Category Headers using in_category and elseif
- related articles using shortcodes
- Insert HTML content in WP Query at specific point
- How can I ask to an existing category?
- How to Sync Menu, Widgets and other masters from Main Website to its Sub Site
- Show category meta in loop on homepage
- How to get selected taxonomy or category ID if using custom walker?
- How to hide widget from certain category
- Category link redirect to custom template page instead of index.php?
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- the_category() doesn’t working in wp_query loop
- Displaying links to all posts of the same category on the post page
- Add class to current post in query_post
- separate posts to have (kind of) 2 blogs?
- create relationship between posts from one category and posts from another category
- Sort posts by child category name
- Intermittent Gutenberg 504 Gateway Timeout when calling REST route to retrieve categories
- display specific category when website loads
- OK to redirect the root WordPress category slug?
- Automatically add custom taxonomy to posts in a category
- WordPress Portofolio Conditional Templating – functions php
- Category page 404s on mobile but not desktop?
- I want to create a custom taxonomy page showing a list of subcategories
- Displaying data from custom fields on a specific category page
- Get WooCommerce product category list in functions.php
- Include a page’s “category” in its URL
- Excluding specific category from custom theme functions
- How can I restrict the categories users can post in, based on user roles?
- How to define a post category undeletable by other users?
- Displaying portions of multiple pages from a given category, in a single summary page
- Change wp_link_pages to link to another page
- Is there a way to order categories?
- Categorizing Just Imported Posts
- Post url rewriting for posts with certain category
- Hide post category name wherever it might be mentioned
- Issue with WordPress category search
- wp_category_checklist won’t show up for non-admin users
- get_the_terms_list output last child only
- Exclude posts with certain tags in category archive
- How to make all post in to a category?
- In a shared site, how to get products in a category from one site to another?
- How to loop through a custom field for each post, & display?
- How to add additional field to Add new category part (without plugin use) [closed]
- show category name before first posts in each category
- Need list of child category post titles sorted by child category
- Lowest catagory link
- Category and tags goes 404
- How can I add a Categories page link to a menu? [closed]
- Media Library filter returns undefined function get_current_screen
- Way to show content of a post, but if exceeds character limit revert to excerpt?
- get IDs from links categories
- get posts from 2 categories. (2 posts)
- Display all subcategories for a product category in woocommerce
- Converting Categories (with ACF fields) to custom taxonomies
- Why does my WordPress index has a category?
- how do I exclude a category foreach