You should use the pre_get_posts
filter for this. For example, you could do this in your theme’s functions.php file:
function limit_category_posts( $query ) {
if ( $query->is_archive() ) {
// Do not do this for the date or category archives.
if ( $query->is_date() || $query->is_category() )
return $query;
if ( $query->query_vars['cat'] == 8 ) {
$query->set( 'posts_per_page', 2 );
}
}
return $query;
}
add_filter( 'pre_get_posts', 'limit_category_posts' );
Related Posts:
- Hot to check if new posts have been published since page load and notify online users?
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- AJAX pagination, update current page
- Limit Widgets to Sidebar ID’s
- Save Search System
- adjust section according to country?
- populate form fields in a loop with ajax
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- How can I get the values of my WordPress $wpdb query in Jquery?
- Ajax request returns ‘Array’. How to output the actual results?
- Ajax load more button for comments wordpress
- Slick + PHP + ACF + JQuery slide reveal not working
- How to add a do_action on refreshing of WP customizer?
- Gravity form built in Captcha
- Menu jumping when calling it via PHP
- Setting value of session with Ajax not working
- Click a radio button must set textfield value
- WordPress Multiple Navigation bars
- [jQuery]Adding shortcode
- multiple taxonomy select display only one in front end
- Display parent and child taxonomies in separate drop down select fields
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Add / Update Custom Fields After Select Pictures in Media Window
- Post repeating with infinite scroll
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- How to disable controls in theme customizer?
- Sort by page information by Ascending Numbers
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- JQuery calling a Custom PHP function (Works in Dev but not in WordPress)
- Jquery function working in Dev Console but not otherwise [duplicate]
- Form Security: nonce vs. jQuery
- How do I Import / Upload Files with jQuery AJAX?
- WordPress admin-ajax.php 400 bad request
- Why does wp_head hook my functions to the beginning of my source code?
- WordPress Ajax Call inserting data but success response false
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- Ajax contact form return 0
- How can i display a jquery slide on front page
- AJAX – Returning Two JSON Objects with One PHP Function
- Pull GetOption() variable into jQuery dynamically created html
- Royalty-Free Sliders used in theme development
- How to list posts from a plugin taxonomy?
- Error – ‘create_function is deprecated’ [closed]
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Counting Search results, and displaying the offset per page
- Unset session variable on page reload / setup but exclude AJAX
- How to get post ID in a Page?
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress Ajax Always returning 0
- Is it save to use eval for a jQuery callback method coming from the database?
- Jquery window.send_to_editor function
- Double jQuery loaded
- Trying to prepend a Hashtag symbol to the_tags links [closed]
- Flexslider won’t work on WordPress
- Function won’t run onclick using Ajax
- Pagination broken on is_front_page()
- Javascript not loading on certain page
- Theme not calling Jquery properly
- How to keep track of when a vote is cast?
- WordPress plugin admin page – using WordPress function in linked php file
- How to add drag and drop functionalities to a div inside option panel
- How to make jquery count down timer function manually editable
- A $_POST should occur when submit form but is not?
- My jQuery Ajax form submit is still refreshing page?
- jQuery Ajax PHP function call returning [object Object]
- How to use the wpsnonce clone post link?
- change the default order of posts only for specific categories
- Shortcode to pull posts
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Output votes to div dynamically in wordpress
- Get uploaded image and attach it to the new post
- Admin-ajax php not working on new wordpress version
- How to add post thumbnail dynamically using Jquery?
- Proper way to use WordPress function with AJAX PHP file
- calling function in external js file
- Posts are not looping through correctly
- jQuery accordion menu
- JS file is not loading when i put wp_head() and wp_footer
- Live search from database table
- How to refresh a page from jquery [closed]
- Angular not defined [closed]
- Add a counter for mouseovers (custom field)
- Accessing an API with jQuery and AJAX
- Saving a post ID to use in a form elsewhere on website
- Removed jQuery script from header.php , any problems?
- posts_nav_link pulling in multiple post types
- Unexpected token ILLEGAL, even on clean install – jquery-issue?
- Set cookie for visitor
- Remove Post if Advanced Custom Field is checked to fix paging
- How to echo the_title from an array of posts?
- Wrap posts p tags in div
- Execute Jquery when a specific page in my plugin is loading
- Admin Menu new tab external link
- Replacing WordPress Icons (menu,icons32, etc)?
- Covert WordPress Blogname into JQuery
- How to break up php code to avoid echo