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
- Multiple queries and pagination
- Loop Performance > JSON files vs. WP_Query vs. REST API
- Two loops on archive page
- Loop Split two Columns
- How to order posts by title after they have already been sorted by category
- Pretty urls for custom pagination
- Excluding pages in WP_query using ACF
- reset to main loop doesnt work
- Multisite pagination issue by multi query archive 404
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Display most popular in the past two days
- Custom Pagination in Shortcode with WP_Query
- Some doubts about how the main query and the custom query works in this custom theme?
- Search form not working with custom query?
- meta_query not working as expected
- Pagination inside of a edit page
- How to : pagination in 3 different custom loops on the same page
- Avoid repeated post on page 2 when excluding one on page 1
- Post loop for all taxonomy terms
- WP Query to have sticky posts first, with pagination and having a joint ‘posts per page’ arg with main loop
- New WP_Query calls Pre_get_posts filter twice
- How to make search for posts using get method?
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- Stuck in the query loop
- Conflict with get_posts and the_content
- Multiple Loops on category.php with pagination on last loop
- How to get list of posts from permalinks?
- Pagination on static Posts page
- Custom post type archive pagination query issue
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- New WP_Query loop in admin causes problems
- How to list posts with disabled/closed comments, with pagination?
- Custom loops, sticky posts, and pagination nightmare
- How to make a second query offset -2 from current post
- pagination not working for category.php (custom post types in categories)
- Running main loop 2 times with conditional statement
- Pagination for blog posts reloading same page [closed]
- paged variable not working for category/custom post archive
- Only display post if published in last 24 hours?
- Need to convert string of term ids into comma separated integers for use in an arguments array
- WordPress Blog Posts with Pagination inside a Page/Post
- how to access query string in wordpress?
- WordPress | Date not always appear [duplicate]