• Resolved sanniel

    (@sanniel)


    Hello!

    Is it possible to set a number of default stores that are always included in the result list?

    I have tried doing this by sql, and got as far as the query below, but it simply returns zero results. (As a curiosa, the query works perfectly when run with sample lat-lng values in phpmyadmin, just not in the plugin)

    SELECT lat, lng, ID, distance FROM (
    SELECT post_lat.meta_value AS lat, post_lng.meta_value AS lng, posts.ID, 
    ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) ) AS distance
    FROM $wpdb->posts AS posts
    INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
    INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
    WHERE posts.post_type = 'wpsl_stores' AND posts.post_status = 'publish'
    GROUP BY posts.ID, post_lat.meta_value, post_lng.meta_value $sql_sort)
    UNION  
    SELECT lat, lng, ID, distance FROM (
    SELECT post_lat.meta_value AS lat, post_lng.meta_value AS lng, posts.ID, 
    ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) ) AS distance
    FROM $wpdb->posts AS posts
    INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
    INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
    WHERE posts.post_type = 'wpsl_stores' AND posts.post_status = 'publish' 
    AND (posts.ID = '1706' OR posts.ID = '2835')
    GROUP BY posts.ID, post_lat.meta_value, post_lng.meta_value)

    Regards,
    Susanna

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    I think the easiest way to add fixed location is by using the wpsl_store_data filter.

    It allows you to access the data just before it’s returned. So in this case you can hard code a list of store ID’s, collect the meta data with get_post_meta, and then merge the data from the fixed location with the location collected by the SQL query.

    Thread Starter sanniel

    (@sanniel)

    Thank you, I have now solved it by multiple sql calls and an array_merge. As that required editing the class-frontend.php, will this custom code disappear in the next plugin updates?

    Plugin Author Tijmen Smit

    (@tijmensmit)

    If you install an update, then the plugin files are replaced.

    You can run a custom SQL query with the wpsl_sql filter.

    Hi i think my issue is similar. i have a number of online stores I want to always come up when a customer puts their address in to find their closest store. I have tried just add the country as the address but this doesn’t seem to work. Is there a quick and easy fix to this issue as I am not a web developer I don’t understand any of the solutions you have written above. My website is http://www.odorex.co.nz

    Hey @tijmensmit,

    Can you elaborate a little more on how to add a fixed store to the list of results. If you could provide a code example, that would be awesome!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Always include default stores in result list’ is closed to new replies.