I have a website that is integrated with Wordpress and the ACF plugin. I need some help writing an SQL statement to query the data I need. This is the statement so far
"SELECT ID, ( 3959 * acos(cos( radians( ".$_GET[lat]." ) ) * cos( radians( pm1.meta_value))
* cos( radians( pm2.meta_value ) - radians( ".$_GET[lng]." ) )
+ sin( radians( ".$_GET[lat]." ))
* sin( radians( pm1.meta_value) ) ) ) AS distance
LEFT JOIN wp_postmeta AS pm1
ON pm1.post_id = [login to view URL]
AND pm1.meta_key = 'latitude'
LEFT JOIN wp_postmeta AS pm2
ON pm2.post_id = [login to view URL]
AND pm2.meta_key = 'longitude'
HAVING distance <= ".$_GET[radius]."
ORDER BY distance ASC;"
This statement queries Wordpress posts and returns them in order of their distance using LAT/LONG co-ordinates.
I need to add some extra filters to this query. I need to also filter by:
- (ACF Field) event_start_date => today
- WP post status = published
That's it! Thank you.