If you’re running this custom query in place of the normal main query, you should instead alter the main query before posts are fetched, via the pre_get_posts
action. This would go in your theme’s functions.php
, or a custom plugin:
function wpd_private_posts_in_categories( $query ) {
if ( $query->is_category() && $query->is_main_query() ) {
$query->set( 'post_status', array('private', 'publish') );
$query->set( 'posts_per_page', 20 );
}
}
add_action( 'pre_get_posts', 'wpd_private_posts_in_categories' );
You can then run the normal loop in your category template and pagination will work properly, private posts will be included in the calculations.
Related Posts:
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- Order by DESC, ASC in custom WP_Query
- Exclude or Include category ids in WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- Use WP_Query with a custom SQL query
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- How to query for a week using key => value WP_Query argument notation?
- Pagination not working for Custom search form & custom result template
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- How can I style future post?
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Looping through tabular data
- Using next/previous_posts_link with customised search
- How to create/modfiy WP_Query to search in post title OR custom field?
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Array Chunks and Inserting Varying HTML in WP_Query
- Filter user list that meta_value is empty
- How to output different posts per page?
- Modifying the Search Results
- WP_Query times out
- ACF – Get lowest & highest value from field
- Offset Page Loops and Pagination
- How to find a post id using the post_excerpt?
- wp_query add arguments using array_push if variable met
- tax_query: Order by slug?
- Comparing dates in custom field
- reducing the amount of wp_query calls
- WP_Query filter and order by meta ordering by wrong joined table
- Querying A Post That Includes Two Taxonomies Using JSON Rest API
- WP_Query condition affects posts_per_page count
- Use post object from first query in second query
- Order by title without taking into account ‘the’
- Set global $wp_query/$post variable for dynamic page generation
- Display tags with random thumbnail from selection of posts with that tag
- slow WP_Query for non-admin user
- Changing sort order for presentation by Jetpack infinite scroll
- Why does get_posts only show results for Admins or logged-out users?
- How to store and receive variables in WP sessions?
- How to list posts with disabled/closed comments, with pagination?
- Limiting number of related posts
- Category ‘pad_counts’ & ‘parent’ conflict
- how would i change post->ID to work correctly when querying pages?
- WP User Query with Custom Fields and Search Results
- Pagination works in custom query loop but it doesn’t work in shortcode
- Event with multiple dates, display events chronologically
- How to exclude Sticky from Recent Post?
- Display if author page is author page of current user
- WP_Query order by not working properly due to category I believe
- Modify WP_Query using pre_get_posts but only for frontend query?
- WP_Query to get post on frontpage
- When listing child pages run out of memory
- Function to retrieve IDs of posts, cache results, and improve wp_query
- parse_tax_query causing Navigation Menu To Disappear
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Search.php – return number of results but cannot loop through
- Creating ‘posts page’ loop based on the page itself
- How to get pages of parent (non-recursive)?
- wp query remove posts from query then update max pages and posts found
- WP_Query Orderby meta_key and hide some meta_key
- Show X taxonomies of the latest published posts
- Combine query in WP_User_Query()
- Combine relationship posts with existing wp_query
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- What is the equivalent WP_Query of a SQL Query?
- create custom shortcode wp and put php code in
- WordPress Query custom ordering by temporary variable
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- How to get only present and past posts with post_date
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- Load WP Query with Ajax
- How to get_comments() ordered by date and parent?
- WPQuery loop not giving expected output
- WP Query filters active on wrong query
- Not able to fetch woocommerce variation sales products for particular category products
- Global page ID variable empty error
- WordPress tax_query ignoring relation OR
- pagination functions are not working
- Gather same custom field values in one value in a select tag with wp_query
- Fetch only categorized posts
- Wrap group of wp query posts to parent div by date/year
- Continue loop after $queryObject
- Order Posts By Youtube Views
- WP Query with sticky posts and tax_query
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- Declare inline background image in functions.php
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- Getting Year & Date inside wpdb [duplicate]
- loop through custom post types with meta data
- Looking for a way to exclude frontpage and nav menu from query filter
- Using Query In Post Type Archives
- Query posts by custom fields
- WP Query Obj: Set value to be unequal | Hide media by admin
- Get posts by meta value except one post [closed]
- Display Featured image from custom post type category (custom taxonomy) wise