Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134837

jesperb on "Custom filter query with meta_values that is in an array?"

$
0
0

Hey,

Been staring at this too long so I figured I'd post here to see if I'd be able to get a push in the right direction.

The rundown:
I'm trying to limit the regular WP_Query to only return posts within a certain radius of the user. The post's got a "location"-field (advanced custom field f.y.i). And I'm saving the users' latitude and longitude as a cookie.

However, the posts' locaiton is saved in an array:

Array (
[address] => DAL 221, 830 60 Föllinge, Sverige
[lat] => 63.68805485609542
[lng] => 14.087100587500004
)

How the heck do I select them separately this way? Am I even on the right way here?

What I've got so far:

function filter_where_custom() {

                    $latsearch = $_COOKIE["lat"]; //user latitude
                    $lngsearch = $_COOKIE["long"]; //user longitude
                    $distance = 2; //set radius of 2km
                    $lng = '?????'; //post longitude
                    $lat = '?????'; //post latitude

                    $where .= "
                    AND
                    (6371 * acos( cos( deg2rad($latsearch) ) * cos( deg2rad( $lat ) ) * cos( deg2rad( $lng ) - deg2rad($lngsearch) ) + sin( deg2rad($latsearch) ) * sin( deg2rad( $lat ) ) ) ) < $distance
                    ";
                    return $where;
                }

Hope my question isnt too vague, thanks for the help!


Viewing all articles
Browse latest Browse all 134837

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>