I'm trying to exclude from the search results a custom post type, called "Houses", as this is confidential information from the registered users.
For this CPT , I've checked the Types custom post setting called "exclude_from_search" which is supposed to allow the functionality I want.
With this setting enabled, the results page after a search, is still listing the non wanted "Houses" CPT.
Any idea about what might be wrong?
Thanks for your help,
Miquel
Dear Miquel,
The option "exclude_from_search" is for wordpress build-in search feature.
How do you setup the search result page and search form?
Have you tried to deactivate other plugins, and switch to wordpress default theme, and test again?
Dear Luo,
I've managed to avoid that House CPT instances are included in the search query, by adding the WordPress action below. I don't know yet, what it is for the "exclude_from_search" setting....
add_action('pre_get_posts','KY_SearchFilter');
function KY_SearchFilter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set( 'post_type', array('post','page','product','portfolio') );
}
}
}
Another setting with an unexpected behaviour is the "publicly_queryable" setting, which can be set up with Types, when creating a CPT.
When this setting is disabled, on CRED, you can not select this CPT on the select box : "Choose the type of content the form will create or modify".
This setting is supposed to only affect the frontend queries, and not the queries when designing a new form on CRED.
I set this thread as resolved as I've found work arounds for both issues.
Thanks,
Miquel
As a final finding, the CPT "publicly_queryable" setting is ignored or modifed by the ACCESS plugin.
As soon as the Post Type is set to "Managed by Access" (in the ACCESS plugin configuration page), it becomes publicly queriable in the frontend, despite of the setting in the TYPES plugin options .
Writing here just in case it can help to improve the plugin behaviour,
All the best,
Miquel