mysql - Unknown column 'lat' in 'field list' -
i'm tweaking wp_query
quite lot add_filter
function.
i'm getting error wordpress: unknown column 'lat' in 'field list'
the final sql output this:
select sql_calc_found_rows wp_posts.*, ( 3959 * acos( cos( radians(52.486243) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-1.890401) ) + sin( radians(52.486243) ) * sin( radians( lat ) ) ) ) distance , lat latitude , lng longitude wp_posts inner join wp_term_relationships on (wp_posts.id = wp_term_relationships.object_id) inner join wp_postmeta on (wp_posts.id = wp_postmeta.post_id) inner join wp_postmeta mt1 on (wp_posts.id = mt1.post_id) inner join lat_lng_post on wp_posts.id = lat_lng_post.post_id 1=1 , ( wp_term_relationships.term_taxonomy_id in (2) ) , wp_posts.post_type = 'event' , (wp_posts.post_status = 'publish') , ( (wp_postmeta.meta_key 'date_%_start-date' , cast(wp_postmeta.meta_value signed) <= '20140704') , (mt1.meta_key 'date_%_end-date' , cast(mt1.meta_value signed) >= '20140627') ) , lat_lng_post.lat = lat , lat_lng_post.lng = lng , substr(wp_postmeta.meta_key, 1, 6) = substr(mt1.meta_key, 1, 6) group wp_posts.id having distance <= 18 order distance asc limit 0, 10
i thought and lat_lng_post.lat = lat
, and lat_lng_post.lng = lng
lines have sorted unknown column issue?
does know what's wrong query?
[edit]
lat , lng columns in wordpress db in custom table. table made using this:
create table if not exists 'lat_lng_post' ( 'post_id' bigint(20) unsigned not null, 'lat' float not null, 'lng' float not null ) engine=innodb;
[edit 2]
just noticed under error sql query outputted different the sql being shown var_dump($wp_query->request)
.
below sql showing below error `unknown column 'lat' in 'field list'.
select wp_posts.*, ( 3959 * acos( cos( radians(52.486243) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-1.890401) ) + sin( radians(52.486243) ) * sin( radians( lat ) ) ) ) distance , lat latitude , lng longitude wp_posts 1=1 , wp_posts.post_type = 'acf-field' , ((wp_posts.post_status = 'publish')) , wp_posts.post_name = 'field_535e6b9ffe3da' , lat_lng_post.lat = lat , lat_lng_post.lng = lng group wp_posts.id having distance <= 25 order distance asc limit 0, 1
this quite different want querying reason.
i'm not sure if issue may add filter
functions being added query breaking it?
you indicate in first edit lat column comes lat_lng_post, trying select wp_posts - not exist in table, hence unknown column error.
i can't see obvious way make query work information you've given.
however, if there way join lat_lng_post wp_posts on e.g. wp_posts.id matching lat_lng.post_id follows, joining tables projecting relevant fields lat_lng:
select wp_posts.*, ( 3959 * acos( cos( radians(52.486243) ) * cos( radians( lat_lng.lat ) ) * cos( radians( lat_lng.lng ) - radians(-1.890401) ) + sin( radians(52.486243) ) * sin( radians( lat_lng.lat ) ) ) ) distance , lat_lng.lat latitude , lat_lng.lng longitude wp_posts inner join lat_lng on (wp_posts.id = lat_lng.post_id) 1=1 , wp_posts.post_type = 'acf-field' , ((wp_posts.post_status = 'publish')) , wp_posts.post_name = 'field_535e6b9ffe3da' group wp_posts.id having distance <= 25 order distance asc limit 0, 1
Comments
Post a Comment