"Private" Pages are showing up in Search results

Hello!

When using the Classic Search Element or Search Modal Element, pages that are set to private show up in the results. I only want public pages to show in these results.

If there is documentation on setting up search parameters, please let me know (I couldn’t find any)

This is the site: https://tambouretwellness.com/

Thank you,
Troy

Hi Troy,

Those search elements are using wordpress search function.
You can use wordpress filters to exclude your private pages.

You can try adding the code below in your child theme’s functions.php file.

//Exclude pages from WordPress Search
if (!is_admin()) {
    function wpb_search_filter($query) {
        if ($query->is_search) {    
            $query->set('post_status', 'publish');
        }
        return $query;
    }
    add_filter('pre_get_posts','wpb_search_filter');
}

Please add it after this line

// Additional Functions
// =============================================================================

For more information, you refer to the links below



https://codex.wordpress.org/Plugin_API/Filter_Reference

Hope that helps

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.