here is the mysql query you can use to get the result having distance less then your value.
SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude ,
(((acos(sin(([latitude]*pi()/180)) *
sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) *
cos((pm1.meta_value * pi()/180)) * cos((([longitude] - pm2.meta_value)*
pi()/180))))*180/pi())*60*1.1515
) as distance
FROM wp_posts p
JOIN wp_postmeta pm1 ON pm1.post_id = p.ID AND pm1.meta_key = 'latitude'
JOIN wp_postmeta pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'longitude'
WHERE ID = 98
having distance < $_GET['within']
It will return all the post with distance is less then your $_GET[‘within’] value.
Related Posts:
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- WP insert post PHP function dynamically generated Custom Fields
- Having trouble with custom date field for CPT query (WordPress)
- WP_Query search posts by custom post type and custom taxonomy
- creat filter with wp_query
- First custom field value (out of several) displayed twice after query
- WP Query from two Custom Post type fields as statement
- Alike Shortcode using in Custom Shortcode
- Query custom post type that has a serialized relational advanced custom field value
- Sort custom post column by generated value?
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Filter Custom post type by another Custom post type
- Multiple orderby values in WP_Query
- How to use a custom post type as front page?
- Search multiple custom fields by using meta_query
- WP_Query orderby custom field then post_date in one query
- Query custom post type by custom field
- how to filter by last name for custom post
- Search that will look in custom field, post title and post content
- Filtering a WP_Query meta_query by numeric values isn’t working
- Sorting a query by custom field date
- How can I generate a RSS feed based on a custom WP_Query?
- Filtering a WP Query result
- Display Custom Post Type Fields
- Search Custom Post Type with all meta attached?
- How to sort CPT by custom meta value (date), and return posts month by month
- Querying Posts by Taxonomy From Alternate Network Site
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Query by 2 values of a repeater ACF field
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- WordPress query by multiple Custom fields and order by date
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- Get post info inside modal window?
- Include both default and Custom Post Type in query modified inside pre_get_posts
- WP Query group/order by category name
- Adding a span when custom post type is updated
- Inserting data into `post meta` table?
- Display children and grandchildren of a custom post type
- Display posts if a custom field value is equal to another custom field value
- Sort by two dates. Default entry date and custom field if present
- Sort posts based on multiple custom fields
- Calculating Bayesian average for custom post type
- Is it possible to create a shortcode that will query a post based on taxonomies?
- Filtering by Post Meta Custom Fields – Performance
- wp_query to find posts by year and month
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- WP Query—Relationship between two custom post types and their fields
- Create a random unique 6 digit number as custom field for custom post type
- How to dynamically attach pictures to a carousel
- Querying Term Posts in Loop
- query posts and custom post type with meta key
- Use get_post_types to query only custom posts types
- WordPress Orderby Numeric Value Not Working
- Using several custom fields as custom post title
- Get all Posts If has same custom field values in Posts
- Can’t get order_by meta_value_num to work properly
- Custom Post type and Custom Field WP_Query
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Including Custom Meta with posts_where query
- Very Slow Page – How to Optimize # of Queries?
- Custom query to filter posts that have current post as a taxonomy [closed]
- WP_Query: include custom post type only with specific meta value
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- How to make sure content doesn’t display if selection is empty
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Replace text in post from cvs
- wp_query check if integer exists in custom field’s array
- convert custom query to wp_query
- Search / Filter posts on Title/Content OR Tags
- Query & Order posts by custom fields
- Querying Two Custom Post Types with OR Not Working
- How can I get the number of custom post type posts that have a specific attachment image set?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- WP_Query order by custom field, then randomly order some of results
- get_post_meta not working on publishing
- Query custom post type with ACF Date
- Using custom field content as expression in IF statement [closed]
- Including metaboxes from custom post types in global search — continued
- Query Multiple Custom Posts by Custom Fields
- Get Posts by multiple custom fields is not working
- Order Custom Post Type by Custom Field Value
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- Custom post types – meta_query: search lesson which starts sooner
- Post Filtered by Custom Field Value
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- Custom Taxonomy – fields
- post type => ‘any’ not applied my custom queries
- Custom Post By Category
- sorting in wp query based on custom field value
- PHP Notice: Unidentified index
- How to get the posts that my following users are liked?
- Meta_Query refuses to return results
- Linking posts together with Advanced Custom Fields “both ways”