If you want to show Private Posts to non-logged in user then you can try the given code. Also showing Private posts to Non-Logged In User not recommended.
With this approach the private content will expose to all users, which may not be recommended for most cases.
<?php
function include_private_posts_in_search( $query ) {
if ( $query->is_search && ! is_admin() ) {
/**
* Here we have added 'publish' and 'private' post status, we can add more as per the need.
*/
$query->set( 'post_status', array( 'publish', 'private' ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'include_private_posts_in_search' );
Related Posts:
- Search with filters and title
- Search pre_get_posts filter which can handle multiple post types and categories?
- Filter keywords from search query
- Ignore dots when searching in the media library?
- Search results sorted by post types
- Adding id and class to the search input in WordPress search form
- How to apply filter at search of woocommerce products?
- How to edit dashboard search posts button texts for my CPT?
- Filter custom post type using multiple taxonomy dropdowns
- Admin Backend – Search Pages only by title
- Comment search plugin
- Create Search Form to Filter Through Terms
- Map plugin with proximity search compatible with Buddypress
- How to trim white space in search terms?
- conditional search
- How to set a filter search for categories of blog posts in wordpress
- Customising the default wordpress search functionality
- Search with filters
- Modify WordPress search behaviour in backend?
- Re-order search results with posts_orderby filter and post meta value
- meta box loop problem with a search filter
- Remove the post_content search from WHERE clause (and CONCAT sql function)
- Custom search fields and AJAX support
- How we make the filter for fornt end user
- Filter and Search
- Taxonomy search filters
- Filter posts by multiple checkbox categories
- Search and Filter Using Custom Post Type, Custom Taxonomy, and Advanced Custom Fields
- what is __return_false in filters
- Custom theme hooks / filters – passing arguments
- What params are available with the_content filter?
- How to hook wp_list_pages?
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- apply_filters(‘the_content’, $content) alternative
- Changing document title only on a custom page template
- Filter the blog’s title without using global variables
- user_has_cap filter allows edit but will not allow save
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
- How do I pass the value from a foreach loop to an add_filter function? [closed]
- Add guid filter to attachment in media library grid mode
- Pass parameter to the upload_dir filter
- Filter or Hook to catch pre-rendering of post content
- check to see if hook is available
- Private Posts/Pages & Search
- Filter users by custom colum not meta key
- How to allow users to view pending posts of a specific custom post type?
- Remove filter callback: method in class
- How can I exclude tags from category_rss function?
- How to filter meta_values using REST API
- How do I use remove_action on an add_action that uses an array?
- Change the default 10-day expiration for the password protected pages cookie
- Add content as soon starts
- Access get_the_title() from ‘excerpt_length’ filter
- Wrong post_status notice after wp_insert_post_data
- Search filter triggered & sort by custom post type
- How can I replace an oEmbed URL in post with actual embed HTML
- How do you get specific tags from the_content?
- Add a filter inside an action init
- How to display the content HTML of a page without displaying the gallery code as well
- Is it possible to apply_filter on a wp_ajax_ action?
- Apply filters with multiple filters
- Using add_filter to prepend content, result is out of order
- Remove Comment Author Link only for subscribers
- get_posts() interrupt because of filter
- WooCommerce coupon hook argument NULL when using filter woocommerce_get_shop_coupon_data
- How can I edit comment meta value before it is saved?
- Why current_user_can(‘edit_comment’) always true?
- Disable sanitize_file_name on upload without modifying functions.php
- Redirect after post deleted
- How to stop filter from running on the index.php page?
- Filter Media by attached page or blog post in Library
- How to stop DOMDocument destroying embeds?
- How to modify image caption in posts?
- Extend Nonce Lifetime for Specific Nonce Creation
- Run `wp_insert_post_data` on all posts
- How can I pass instance via apply_filters as a parameter?
- Consult array data in REST API Filter
- WordPress add_filter to post_date
- create a shortcode with acf including a filter
- Custom permalink for attachment
- Overriding Generated Attachment Post URL
- Pagination while keeping the filters
- Apply a filter str_replace on specific caracters array in the_content()
- Filter on the day of the week from timestamp
- using filters on the function from class
- Put data in my-account/view-order/id/ page
- add_filter not adding the filter
- Is this correct usage of filters in WordPress [closed]
- child_of not working while searching
- Passing variable from filter
- Filter image and text from post format
- Remove pipe in views admin page filter
- Hooking/Filtering theme name to add theme directory
- How to use filter in this situation, can not modify the structure using filter
- How to use parse_query() to add an additional filter based on content to page search?
- FacetWP was unable to auto-detect the post listing : Having an issue with ACF load choices causing FacetWP error
- add_filter – create_function pb in PHP8
- Woocommerce price filter widget always shows max price of most expensive product in the whole shop
- add_filter( ‘user_has_cap’,’my_function’, 10, 3 ); and call to get_users in my function triggers an infinite loop in user list