gpt4 book ai didi

mysql - 'lat' 中的未知列 'field list'

转载 作者:行者123 更新时间:2023-11-29 12:53:09 24 4
gpt4 key购买 nike

我正在使用 add_filter 函数对 wp_query 进行大量调整。

我从 WordPress 收到此错误:“字段列表”中的未知列“lat”

最终的SQL输出是这样的:

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 ) )
) )
AS distance , lat AS latitude , lng AS longitude
FROM 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 AS mt1 ON (wp_posts.ID = mt1.post_id)
INNER JOIN lat_lng_post ON wp_posts.ID = lat_lng_post.post_id
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (2) )
AND wp_posts.post_type = 'event'
AND (wp_posts.post_status = 'publish')
AND ( (wp_postmeta.meta_key LIKE 'date_%_start-date' AND CAST(wp_postmeta.meta_value AS SIGNED) <= '20140704')
AND (mt1.meta_key LIKE 'date_%_end-date' AND CAST(mt1.meta_value AS SIGNED) >= '20140627') )
AND lat_lng_post.lat = lat
AND lat_lng_post.lng = lng
AND substr(wp_postmeta.meta_key, 1, 6) = substr(mt1.meta_key, 1, 6)
GROUP BY wp_posts.ID
HAVING distance <= 18
ORDER BY distance ASC
LIMIT 0, 10

我认为 AND lat_lng_post.lat = latAND lat_lng_post.lng = lng 行可以解决未知列问题?

有人知道查询出了什么问题吗?

[编辑]

lat 和 lng 是自定义表中 WordPress 数据库中的列。该表是使用以下内容制作的:

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;

[编辑2]

刚刚注意到错误下输出的 SQL 查询与 var_dump($wp_query->request) 显示的 SQL 不同。

下面是显示错误“‘字段列表’中未知列‘纬度’”的 SQL。

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 ) )
) ) AS distance , lat AS latitude , lng AS longitude
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'acf-field'
AND ((wp_posts.post_status = 'publish'))
AND wp_posts.post_name = 'field_535e6b9ffe3da'
AND lat_lng_post.lat = lat
AND lat_lng_post.lng = lng
GROUP BY wp_posts.ID
HAVING distance <= 25
ORDER BY distance ASC LIMIT 0, 1

由于某种原因,这与我想要查询的内容完全不同。

我不确定问题是否可能是由于添加到查询中的添加过滤器函数破坏了它?

最佳答案

您在第一次编辑中指出 lat 列来自 lat_lng_post,但随后您尝试从 wp_posts 中选择它 - 该表中不存在该列,因此出现未知列错误。

我看不出有一种明显的方法可以使查询与您提供的信息一起使用。

但是,如果有其他方法可以将 lat_lng_post 加入 wp_posts,例如wp_posts.id 匹配 lat_lng.post_id 您可以按如下方式执行操作,连接表,然后从 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 ) )
) ) AS distance , lat_lng.lat AS latitude , lat_lng.lng AS longitude
FROM wp_posts INNER JOIN lat_lng
ON (wp_posts.id = lat_lng.post_id)
WHERE 1=1
AND wp_posts.post_type = 'acf-field'
AND ((wp_posts.post_status = 'publish'))
AND wp_posts.post_name = 'field_535e6b9ffe3da'
GROUP BY wp_posts.ID
HAVING distance <= 25
ORDER BY distance ASC LIMIT 0, 1

关于mysql - 'lat' 中的未知列 'field list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24448951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com