Oh dear, that was extremely obvious – there was a missing closing bracket!
Here is the working query.
SELECT ID, (
6371 * acos (
cos ( radians( 35.665833 ) )
* cos( radians( latitude.meta_value ) )
* cos( radians( longitude.meta_value ) - radians( 139.731111 ) )
+ sin ( radians(35.665833 ) )
* sin( radians( latitude.meta_value ) )
)
) AS distance
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta latitude
ON (ID = latitude.post_id AND latitude.meta_key = 'place_latitude')
INNER JOIN $wpdb->postmeta longitude
ON (ID = longitude.post_id AND longitude.meta_key = 'place_longitude')
HAVING distance < 30
ORDER BY distance
LIMIT 0,6;
Related Posts:
- How do you properly prepare a %LIKE% SQL statement?
- $wpdb and MySQL Create Trigger
- wpdb->prepare function remove single quote for %s in SQL statment
- Alternative to mysql_real_escape_string
- Increment value (value = value+1) of $wpdb->update
- wpdb Custom Meta Data with 2 conditions
- wpdb prepare syntax
- SQL query not working in alphabetical post title/content search
- MySQL LIKE not working
- Proper way to work with wpdb to get user’s firstname
- How to check for empty and not a failure
- Database: Custom table: sprintf value for DateTime column
- Converting mysql to $wpdb
- WP_USE_EXT_MYSQL
- wpdb insert and boolean fields
- Join new table with SQL query
- writing inner join in wpdb
- How to split the a table in database?
- MySQL Rank & $wpdb
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How do I join a $wpdb query with user meta using default value if not exist?
- How to translate this mySQL query to $wpdb query
- $wpdb select all meta for each post
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- WordPress(wpdb class) and mysql stored procedures
- Can’t run database query
- Using WPDB->Insert()
- Active DB queries in WordPress?
- How to stop $wpdb from prepending database name
- WordPress $wpdb get posts from category and sort by custom meta
- How to get INSERT errors from $wpdb?
- Getting Error Trying to Create Table
- How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option
- Understanding custom php that reads from WP MYSQL
- How to insert dash (-) into database using wpdb and new_to_publish hook?
- $wpdb->get_var multiple queries in one database check
- List users with the most posts in the last 30 days
- Insert two row in wordpress database
- WordPress $wpdb no result
- PHP variables in mysql query
- MySQL ‘duplicate entry’ error
- User set date and time from frontend doesn’t get stored into database
- Wpdb query with dynamic table name
- get posts whether meta_key exists or not
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- How to search usermeta table
- How to add virtual column in wpdb get_result statement
- wpdb insert into point column in db
- WPDB delivers wrong results from complex queries
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- CONCAT_WS in custom sql query
- MySQL Select within WP Page template
- Saving custom term value to the database in new table
- why is $wpdb->update() causing a DB error from within wp_set_password()
- $wpdb->get_var returns 0
- Initialization of table in database using ‘CREATE … IF NOT EXISTS’
- Access Denied for User ‘root’@’localhost’ (using password: YES) – No Privileges?
- mysql Foreign key constraint is incorrectly formed error
- mysql: SOURCE error 2?
- How to avoid MySQL ‘Deadlock found when trying to get lock; try restarting transaction’
- MySQL IF NOT NULL, then display 1, else display 0
- Repair all tables in one go
- Get the new record primary key ID from MySQL insert query?
- ERROR 1115 (42000): Unknown character set: ‘utf8mb4’
- Error Code: 1290. The MySQL server is running with the –secure-file-priv option so it cannot execute this statement
- Remove Primary Key in MySQL
- Error: Duplicate entry ‘0’ for key ‘PRIMARY’
- Why are simple updates to wp_postmeta’s “_edit_lock” so slow?
- Search multiple meta keys at once
- query to create woocommerce products from images
- Configure WordPress to connect to Mysql DB using SSH tunneling
- Using $wpdb Class to Pull Recent Comments Across a Network
- SQL error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’ [closed]
- Converting MYSQL to WordPress $WPDB
- wp query foreach deleting record returning only first or last item
- mySQL statment count of post in each category and sub category
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Paypal Post IPN handeling nightmare
- Is there a page length limit?
- What’s the sql for this condition?
- Create a form with custom autocomplete address field and CSV import values
- Basic wpdb update question
- WordPress insert query is not working : Showing no Error
- Copy usermeta value where ID matches in the same table
- Some Post Content Does Not Show Up In DB Search
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- Help setting up a sql query
- Help with Related Posts Function
- (WP List Table) How to sort by SKU and Custom Fields?
- How to run SQL query from WordPress ‘WP Crontrol’ plugin
- How to bulk delete a certain part of all wordpress posts
- When I add metadata, metavalue length is added in to the value in some cases
- Where is the HTML-handler part in the wpdb class?
- update_option returns false in AJAX, how to debug?
- wp_postmeta – lot of meta fields
- Delete posts with word count less than x number of words
- MySQL: get post_tag items that are tags (not SEO keywords)
- mysqldump throws: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)
- How do I load a sql.gz file to my database? (importing)