When you’re trying to link a post to another for example, the suggested results are post titles starting with your query string. You may want to get post titles containing your string.
Here is a snippet to change SQL LIKE mode when querying posts via ajax in “Choose Place” dropdown
/**
* Change SQL LIKE mode when searching for a Place from String% to %String%
*
* @param $where
* @param $search
* @param $post_type
* @param $custom_field
*
* @return array|string
*/
function my_prefix_cp_search_posts_query_where($where, $search, $post_type, $custom_field){
global $wpdb;
if ( $search != '' ) {
$where = explode(' AND ', $where);
foreach ($where as $key => $w){
if(strpos($w, 'p.post_title LIKE') !== false){
unset($where[$key]);
}
}
$where[] = $wpdb->prepare( "p.post_title LIKE %s", array( '%' . $search . '%' ) );
$where = implode( " AND ", $where );
}
return $where;
}
add_filter( 'geodir_cp_search_posts_query_where', 'my_prefix_cp_search_posts_query_where', 10, 4 );