Forum: F.A.Q

This forum is closed for new topics. However, you can still search for a solution in the old topics. For technical support and general questions related to GEO my WP plugin and its core add-ons please use the support forum.

Integrate geo search with wordpress search

Home Forums F.A.Q Integrate geo search with wordpress search

This topic contains 14 replies, has 7 voices, and was last updated by  Wilwong 2 years, 4 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #34189

    forrandomask
    Participant

    Hi There,

    Thanks for this great plugin and update!

    My question is on how to integrate geo search with wordpress search. I would like users to search for a specific post in a specific geolocation.

    I think this is not available yet as a functionality. Can I get this functionality by pulling a specific function in the plugin and using it with wordpress search function?

    thanks
    Argun

    #34202

    bahawolf
    Participant

    I was just coming on to ask this very question. – I’m curious as well.

    Thanks!

    #34201

    Eyal Fitoussi
    Keymaster

    Hi,
    I am not sure how to go about that. I will take a look and see if there is a way to do that.

    #34200

    joesed
    Participant

    I am no coder for sure, but I think this might be possible using something like this in the query:

    $query = new WP_Query( ‘s=keyword’ );

    http://codex.wordpress.org/Class_Reference/WP_Query

    #34199

    bahawolf
    Participant

    Hey there!

    Is there an update to this by chance?

    Thanks!

    #34198

    Eyal Fitoussi
    Keymaster

    Hi,

    How exactly do you want this to work? since there is an input field that should be used for keyword. so where would the address go? or based on which location would the search query the posts.

    #34197

    forrandomask
    Participant

    Hi Eyal

    Thanks for following up with this.

    My view on how to use this is:

    Site will determine where the user is based on the IP address and hence user’s city. Search results should return related posts in that city. User might prefer to change the location by clicking on something like “Change Location” and then enter the address and radius information.

    In short, the site should know user’s location based on users IP or pre-defined location, so that search can return related posts around user. I hope this helps.

     

    #34196

    aseawright
    Participant

    I’m also looking for something similar. I’m not much of a coder, but would like to be able to use Geo my WP to filter my the posts on the front page of my blog by detecting the users location, or by having the user select their own location. I’m not interested in mapping, but I would like the “search results” to match the template I’m using; which is a Pinterest style theme.

    #34195

    joesed
    Participant

    Personally, I’m not looking to integrate wordpress search.

    I intend to use the advanced search function (available in the premium version of GeoMyWP) when it’s released. I think by using custom taxonomies to guide users search together with allowing them to enter their location, this is the best way to produce good (relevant) results to them.

    But one feature which would be super cool would be the ability to provide ajax at the front end (similar to the way the back end) prompts users when they type a location. That is, if the front end could let the user have options based on what they’ve typed already, that would be cool.

    For example, if the user starts typing 90210, then Beverly Hills, CA 90210 is displayed as one of the options.

    This is a really great plugin. I think we need to remember that a huge amount of work has already gone into it before we ask for too many new features! Just my opinion.

    Cheers, Joe

    #34194

    forrandomask
    Participant

    Hi,

    Any update on this any chance?

    thanks

    #34193

    Eyal Fitoussi
    Keymaster

    @forrandomask and @aseawright,
    i am not sure if you are aware of the “current location” widget/shortcode. You can use it to display the user’s current location. It will show his location if exists (in cookies) otherwise will display “get your current location”. Users can get/edit their current location by clicking on the locator icon or manually entering it. Once getting the location it will be saved via cookies. Based on that location, once a user goes to a search page (page with search form shortcode) it will automatically display results near his location.

    if you want to filter the WordPress’s search engine results based on the location you can try using the code below:


    function query_search_by_distance($query) {
    global $wpdb;
    /* check if search query */
    if ($query->is_search) {
    /*get posts within a certain distance from the user current location */
    $total_results = $wpdb->get_col(
    $tata = $wpdb->prepare("SELECT wposts.*, ROUND( 3959 * acos( cos( radians( '%s' ) ) * cos( radians( wposts.lat ) ) * cos( radians( wposts.long ) - radians( '%s' ) ) + sin( radians( '%s' ) ) * sin( radians( wposts.lat) ) ),1 ) AS distance
    FROM " . $wpdb->prefix . "places_locator wposts
    HAVING distance set('post__in', $total_results );
    $query->set('orderby','post__in' );
    }
    return $query;
    }

    add_filter('pre_get_posts','query_search_by_distance');

    copy and paste it into you functions.php file.
    the script hooks into the wordpress’s search engine. Before displaying the results it will run an additional query that will get all posts that have location and within the radius of 50 miles(you can change that) from the user’s location. it will grab the latitude and longitude of the user which saved via cookies.
    Then when having the results in an array , the search query will filter it’s results based on the keyword the user enters and based on the posts that we have from the first query.
    Give it a try.

    #34192

    Eyal Fitoussi
    Keymaster

    @joesed,
    Thank you for the kind words.

    I intend to use the advanced search function (available in the premium version of GeoMyWP) when it’s released. I think by using custom taxonomies to guide users search together with allowing them to enter their location, this is the best way to produce good (relevant) results to them.

    I am not sure what you mean when saying “advanced search function”. i am not sure if you know but you can use taxonomies/categories to filter results with the free version as well.

    However, the autocomplete in the fron end is already exist in the premium version. just need few bug fixs.

    and the premium version is actually ready. the new site is what keeps it delayed. it is taking forever with all the information goes in there, the new design, adn the membership area.

    #34191

    Roger
    Participant

    @Fittoussi, your proposed function is exactly what I am looking for, however when pasting it in my functions.php it unfortunately doesn’t seem to work. Seems the quotes in the $tata function are causing an issue, can you check? Also is the $total_results complete?

    It would be really great if I can get the working code as this is the last thing I need to progress with my current project!!. Here’s the code I copied from above:

    function query_search_by_distance($query) {
    global $wpdb;
    /* check if search query */
    if ($query->is_search) {
    /*get posts within a certain distance from the user current location */
    $total_results = $wpdb->get_col(
    $tata = $wpdb->prepare(“SELECT wposts.*, ROUND( 3959 * acos( cos( radians( ‘%s’ ) ) * cos( radians( wposts.lat ) ) * cos( radians( wposts.long ) – radians( ‘%s’ ) ) + sin( radians( ‘%s’ ) ) * sin( radians( wposts.lat) ) ),1 ) AS distance
    FROM ” . $wpdb->prefix . “places_locator wposts
    HAVING distance set(‘post__in’, $total_results );
    $query->set(‘orderby’,’post__in’ );
    }
    return $query;
    }
    add_filter(‘pre_get_posts’,’query_search_by_distance’);

    Thanks in advance!!!

    #34190

    Eyal Fitoussi
    Keymaster

    Hello Rogier,
    The script above seems to be broken or missing content.

    I just done writing this script. The script modify the main search query and look for results based on the keywords entered and the user’s current location ( must exist in cookies by using the “Current Location widget/shortcode ).

    Together with that there is a script that adds the distance value of each post from the user’s current location into the post title.

    Simple copy paste of the code into function.php will work. However, you can change some values in the script such as the radius value, the units ( miles or kilometer ) and the order by.

    Let me know if it works.

    Thank you

    #55929

    Wilwong
    Participant

    Hi Eyal Fitoussi,
    thanks for your input, i am looking for solution for the same problem as well. The link of your script is broken, it will appreciated, If you can post the script again.
    Many Thanks.
    Wil

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.