Try this:
/**
* Exclude GD CPTs from WP Search.
*/
function gd_snippet_wp_search_exclude_cpts( $wp_query ) {
if ( is_admin() || empty( $wp_query ) ) {
return;
}
if ( ! ( $wp_query->is_main_query() && $wp_query->is_search() ) ) {
return;
}
if ( geodir_is_page( 'search' ) ) {
return;
}
$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
$post_types = geodir_get_posttypes();
if ( ! empty( $in_search_post_types ) && ! empty( $post_types ) ) {
$search_post_types = array();
foreach ( $in_search_post_types as $post_type ) {
if ( ! in_array( $post_type, $post_types ) ) {
$search_post_types[] = $post_type;
}
}
$wp_query->set( 'post_type', $search_post_types );
}
}
add_action( 'pre_get_posts', 'gd_snippet_wp_search_exclude_cpts', 10 );
You can add that as a snippet with the code snippets plugin:
https://wpgeodirectory.com/docs/useful-plugins/#snippets