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
- Search multiple custom fields by using meta_query
- 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 result
- Display Custom Post Type Fields
- Querying Posts by Taxonomy From Alternate Network Site
- 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
- WP Query group/order by category name
- Calculating Bayesian average for custom post type
- wp_query to find posts by year and month
- How to dynamically attach pictures to a carousel
- WordPress Orderby Numeric Value Not Working
- Including Custom Meta with posts_where query
- Very Slow Page – How to Optimize # of Queries?
- WP_Query: include custom post type only with specific meta value
- WordPress custom loop filter by meta_key and value with serialize data
- Replace text in post from cvs
- Query & Order posts by custom fields
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- get_post_meta not working on publishing
- Using custom field content as expression in IF statement [closed]
- Query Multiple Custom Posts by Custom Fields
- Prioritize posts in query by meta keys?
- WP_Query orderby and tax_query
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Ways to Query Custom Post Types?
- Possible to filter custom post type with multiple meta data?
- Loop increase number
- Is This Code Efficient – Or is there a better way?
- How to get specific post meta by title or id
- Get data from PHP to JavaScript to set position of each post on front page
- Undefined $post in wp_query
- Custom post type and custom taxonomy 404 on page 2
- List latest post out of 2 custom post types
- Group by custom field value (start and end times)
- How do I get the index for a custom post?
- Filtering custom posts by custom fields (ACF) [closed]
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- How do I list a custom field and custom taxonomies for each result in a loop?
- Create an user checklist system for a course plateform using ACF Pro and ACF Extended
- set object terms after some some time of published post – functions.php
- Change search query in wordpress custom post type
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- WP_Query get always custom post_type for first
- How can I query and sort custom-post type using WP_Query
- Meta query and compare “!=” not working as expected
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- How select query is generated in a Custom Post Type?
- Filter posts by their related field’s custom field
- Query custom post type and custom field by URL parameters
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- meta query multiple values for the same key
- Custom post types – meta_query: search lesson which starts sooner
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- Custom Taxonomy – fields
- sorting in wp query based on custom field value
- Linking posts together with Advanced Custom Fields “both ways”
- CPT post doesnt shows tags and category on backend admin page
- WordPress query in which condition uses custom field
- Error in WP Query. If variable is empty it is displaying previous post value
- get_post_meta for Custom Post Type ( CPT )
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- Show first posts with custom field not empty and order all by title
- Get month and day from a Date Picker custom field
- Is it possible to add query parameters on the archive page?
- Show Custom Post Type taxonomy term that matches custom field
- WP_Query and two custom fields returns no posts
- Storing/querying custom date data
- Query child posts on parents single.php?
- Query Posts From Multiple Post Types
- Order by custom field attribute
- WordPress can only query up to 766
- Custom Post-type not returning the right child_of
- Select Menu for Custom post Type does not save
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Code in custom widget queries all posts, when it should only query the current post
- Get Posts ordered by a date custom meta field
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Load posts via AJAX without draft status