gpt4 book ai didi

php - 自定义帖子类型的Mysql SELECT自定义字段(post_meta)

转载 作者:行者123 更新时间:2023-11-30 21:35:29 25 4
gpt4 key购买 nike

我正在尝试查询 Wordpress 帖子。

我创建了一个自定义帖子类型 People。每个 people 帖子都有自定义字段 nameagelocationbirthday 等.自定义字段是使用高级自定义字段插件创建的。

我想查询 People 自定义帖子类型的所有自定义字段。

我想要这样的输出:

+----+-------------+-----------+--------+-----------------------------+----------+-----+
| id | post_title | name | age | location | birthday |
+----+-------------+-----------+--------+-----------------------------+----------+-----+
| 1 | SAMPLE | some_name | XX | sample_location | 10/07/1980 |
| 1 | SAMPLE | some_name | XX | sample_location | 10/07/1980 |
| 1 | SAMPLE | some_name | XX | sample_location | 10/07/1980 |
| 1 | SAMPLE | some_name | XX | sample_location | 10/07/1980 |
| 1 | SAMPLE | some_name | XX | sample_location | 10/07/1980 |
+----+-------------+-----------+--------+-----------------------------+----------+-----+

执行此操作的正确语法是什么?

我试过:

SELECT * 
FROM `wp_posts` , `wp_postmeta`
WHERE `post_type` = 'people'

但这列出了所有 wordpress 常规帖子字段。

有人可以帮忙吗?

最佳答案

这里是任何人可能有同样问题的解决方案!

SELECT posts_people.ID AS people_ID,
posts_people.post_title AS people_post_title,
(select meta_value from wp_postmeta where meta_key = 'name' AND post_id = posts_people.ID) as name,
(select meta_value from wp_postmeta where meta_key = 'age' AND post_id = posts_people.ID) as age,
(select post_title from wp_posts where ID = SUBSTRING_INDEX(SUBSTRING_INDEX((select meta_value from wp_postmeta where meta_key = 'location' AND post_id = posts_people.ID),'";',1),':"',-1)) as location,
(select meta_value from wp_postmeta where meta_key = 'birthday' AND post_id = posts_people.ID) as stelexos_kinito
FROM wp_posts AS posts_people
WHERE post_type = 'people' and post_status = 'publish'

关于php - 自定义帖子类型的Mysql SELECT自定义字段(post_meta),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54056789/

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