Alter Search query for wordpress

I want to alter my wordpress search query. I have installed a plugin Post Meta Search

It alters the wordpress search query using following code.

function modify_wp_search_where( $where ) {

if( is_search() ) {

    global $wpdb, $wp;

    $where = preg_replace(
        "/($wpdb->posts.post_title (LIKE '%{$wp->query_vars['s']}%'))/i",
        "$0 OR ( $wpdb->postmeta.meta_value LIKE '%{$wp->query_vars['s']}%' )",
        $where
        );

    add_filter( 'posts_join_request', 'modify_wp_search_join' );
    add_filter( 'posts_distinct_request', 'modify_wp_search_distinct' );
}

return $where;

}

add_action( 'posts_where_request', 'modify_wp_search_where' );

I need help to change the query so that i can give range of postmeta(latitude and longitude) i.e. post.latitude > latitude+10 and post.latitude < latitude-10 and same for longitude.
I need to know what should the following query become

$where = preg_replace(
        "/($wpdb->posts.post_title (LIKE '%{$wp->query_vars['s']}%'))/i",
        "$0 OR ( $wpdb->postmeta.meta_value LIKE '%{$wp->query_vars['s']}%' )",

Read more here: Alter Search query for wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *