The solution I found is in the pre_get_posts function:
I added:
if ( is_user_logged_in() ) {
$query->set( 'post_status', array('private', 'publish'));
}
Full code for function:
/*------- START add webinars custom post type to the main query loop----------*/
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
// show private posts to admins too.
if ( is_user_logged_in() ) {
$query->set( 'post_status', array('private', 'publish'));
}
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'webinars'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
/*------- END add webinars custom post type to the main query loop----------*/
Related Posts:
- Get All IDs Of A Post Type Using WP_Query
- Show all parents and children in custom post type in right order
- wp_query for displaying attachments with a tag
- How can I pick a single post from the latest 3?
- How do I search inside specific taxonomies in WordPress
- How do you determine if a result in a search query is a post or a page?
- Custom wp_query differs on index page and category page
- Show multiple tax_query from 2 or more post_type in a single code
- paginate_links appearing on page but it doesn’t actually paginate – pagination on a static page with a dynamic `post_type` argument on a static page
- post_type not working when tag__in is present?
- Issue attempting a wp_query_posts with tags
- Custom query for certain post type OR another post type with a certain category
- WP Query Args – Title or Meta Value
- WordPress Pagination Not Working – Always Showing First Pages Content
- Whats the difference between post_limits and pre_get_posts?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Query WooCommerce orders where meta data does not exist
- Query all posts where meta value is empty
- How to get post meta value and post in one query?
- Revolution Slider Orderby Two Custom Fields
- wp query by search in titles only & put the posts in loop
- Get random terms
- Dynamically Override Fancy Title – Part II
- Woocommerce custom loop to show all the products [closed]
- Count posts returned by get_posts in external PHP script
- How to run query inside a class with namespace?
- Pagination 404 errors for author posts query on author.php
- List the 5 most recent child pages
- Meta-value query
- WP_Query compare with dynamic values
- WP Rest API max limit include parameter?
- Adding multiple post queries with parent and children to page – Best Way
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Creating a custom search for a specific post type
- How to add post_distinct filter to WP_Comment_Query?
- How is WP_Query parsed to determine which template to request?
- new WP_Query(), have_posts() return false in user_register hook
- How to filter, restrict and return posts based on custom user meta information
- Masonry, WP_Query & paged – first page repeating, second page not loading
- Query posts intersecting tags and categories
- WP_Query ignoring tax_query when is_singular
- REST API: Limit Read Permissions for Default Endpoints
- Excluding pages in WP_query using ACF
- How to sort post by custom table value
- Pagination on static Posts page
- Posts published last 10 minutes
- Make meta query treat meta_value as 1 or 0
- Getting additional columns from sql
- get all posts associated with a custom taxonomy
- WordPress query posts with multiple post_meta data
- Assign custom parameter to each post in query
- Exclude current post from an array of posts?
- How to set an alternate posts_per_page value for default queries in different templates
- How to add $args to any running wp_query from function.php?
- How to remove only the latest sticky post from the loop
- Query posts using less than
- var_dump of WP_Query object is not empty, while .have_posts() return false
- How to view all posts of current day as default in admin
- How to show list of posts with custom field value (a date) that are coming soon
- Using WHERE on a WP_Query
- WP_Query meta compare must include ALL array values
- How to sort queried pages by an array of page ids?
- How to query for a page, get data, then query for child pages of that page
- How can I change the term “Published” next to # of posts published on WordPress dashboard All Posts page?
- Multiple loops breaking side bar
- $post in wp_query?
- meta_query weird behaviour, static int will work, but not user data
- How can I return only IDs from the `posts` REST endpoint?
- search through “product title” using WP_Query?
- WP_Query no result if keyword contains number
- WP_QUERY order posts by two combined meta_value dates
- Custom WP Query order function possible?
- Order by value of Custom Field using url string
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Is the ‘parse_query’ filter still valid to change filtered content on admin list view?
- I removed the “wp_rm_logs” table and am constantly getting this error
- How to set selected attribute on option after filter query?
- WP_Query returns empty if meta_query has more than 7 values
- Fetching $_POST from Page Template into functions.php
- query.php – multiple is_category functions
- Custom query with post_class filter using current_post not working
- Overwriting auto-appended NOT IN query in WP_Query
- posts_per_page not returning correct number of posts
- Conditionals in WP_Query
- Why WP_Query in functions.php is not working when get_posts works?
- Next / previous posts link doesn’t show up with Posts 2 Posts
- Loop the posts between two dates selected using jquery datepicker
- Passing conditional arrays to WP_Query() [closed]
- query by meta value then date and not empty meta value
- Issue with sorting by post date and custom post type
- wordpress sorting using array merge by price in ascending order but price with 0 must be show last
- Carousel Loop only duplicating
- Remove divs and spans from post content
- Can’t get LIKE to work with wp_query [closed]
- Get all user with both meta_value
- Refresh wp_query with no changes
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- How to choose between hooking into pre_get_posts or into parse_query