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.