Stop overriding the default loop and use pre_get_posts
instead. Like this:
function wpse_247208_custom_category_query( $query ) {
// Return early for any situation you aren't interested in.
if ( is_admin() || ! $query->is_main_query() || !is_category() ) {
return;
}
$query->set( 'posts_per_page', 6 );
// Don't use a global; create a function to populate this value
// I just don't know how you created this value so I wanted to make sure
// it is represented.
$featured_posts_to_exclude = get_featured_posts_to_exclude();
// If we have posts to exclude -- add that argument
if (!empty($featured_posts_to_exclude)) {
$query->set('post__not_in', $featured_posts_to_exclude);
}
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
Related Posts:
- Multiple WP_Query loops with Pagination
- Pagination returns 404 after page 20
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- Pagination with 5 posts per page
- Pagination custom query
- Pagination/infinite scroll with WP_Query and multiple loops
- Pagination Not working on Home Page with 2 Query
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Transient pagination not working properly
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Woocommerce custom loop to show all the products [closed]
- How to bring specific post to front of wordpress loop?
- Pagination stops at page 6
- Paginated HTML Sitemap
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- Multiple Loops Inside a Function
- Storing query variable and then using wp_reset_query
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Five posts from a category in footer
- posts_per_page not working for first page of pagination
- How do I get my custom query to work with search results after the first page?
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- relation OR instead of AND – Filtered term ID’s in loop
- Second loop pagination changes URL, not content
- I am officially missing something about transient posts
- Query Not working as expected
- Paginate pages with dynamic query
- Function the_posts_pagination() not compatible with WP_Query arguments
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Pagination repeating posts on search results
- Pagination inside the blog page not working
- Custom query for custom post type not getting correct post ID
- Custom Query Pagination not working on static front page
- Paging works correctly on local version, but not live?
- Get post Number with local loop and template
- Calling a function with WP_Query only ever brings the first result
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- Pagination returns 404 after page 20
- custom query – offset to pagination
- Pagination not working with WP_QUERY
- No content found on page 2 of pagination with 1 post per page
- wp_query pagination links producing 404
- Loop being strainge
- Pagination in custom query not working [duplicate]
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- WordPress Post Looping? [duplicate]
- How to write a query-function as a query-shortcode?
- Show number of posts AND number on current page (cannot make it work)
- Pagination only showed when no category is set in wp_query
- WP_Query vs get_posts
- WP_query and pagination?
- pagenavi with merged wp_query [duplicate]
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- wordpress query in header won’t reset and corrupts other loops
- posts_per_page not working
- How to use WP_Query to display many posts?
- Order by empty custom field
- Cutom wp_query for geolocation search, pagination not working
- Display most popular in the past two days
- New WP_Query loop in admin causes problems
- Need to convert string of term ids into comma separated integers for use in an arguments array
- Error with function in functions.php?
- difference between querying database and using the loop
- posts archive page – closing WP_Query loop correctly [closed]
- Yoast primary category query modification
- AJAX Breaking Offset Argument In WP Query
- Continue or break the while loop
- Pagination in html table is not working
- Function using get_posts() with tax_query not working when called from functions.php
- WP_query paged pagination with excluded category still counts it
- How to make the ‘request’ filter work?
- How do I stop the same post showing multiple times in a archive?
- Pagination unique to a widget
- Why pagination is not working with tax_query param?
- Finding post ID dynamically on click
- paginate_links method doesn’t show second page of my custom wp_query
- Wp_Query Post per page not working?
- how to get custom attachment url?
- WP_Query & Duplicate entries
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- WP_Query a custom field value bringing back 0 results
- Set Transient on CPT
- Horizontally paginate through sets of blog posts?
- meta_query dates from an array
- Creating array to compare custom field values
- Comments orderby comment date not working
- Switched from query_posts to wp_query, pagination no longer working
- Remove 5 latest posts from the loop
- Exclude post formats in custom loop
- Adding css tweak based on page template
- Show linked products using wp query and woocommerce
- Standard Loop – wp_query
- Custom Wp_query loop takes very long