Select 来自 wordpress posts 的自定义 post 字段 (ACF)
Select custom post field (ACF) from wordpress posts
我创建了一个自定义 post 类型:stock
有现货,我用ACF添加了很多自定义字段
我创建了大约 20 个股票。
现在,我正在尝试为每个 post.
获取不同自定义字段(在 workbench 中)的值
这里有一些字段:prix(价格)、ville(城市)、nombre de chambres(房间数)
我想要的结果:
post_title | prix | ville | nombre de chambres
Title 1 | 20 | paris | 3
Title 2 | 40 | marseille| 4
Title 3 | 30 | royan| 2
etc...
我试过的代码:
SELECT post_title,
(select meta_value from mod803_postmeta where meta_key = 'prix')
FROM mod803_posts
WHERE post_type='stock' AND post_status='publish'
我得到标题和一个名为“select meta_value 来自 mod803_postmeta 的列,其中 meta_key = 'prix'” 但该列是 'NULL'.
谢谢
因此,这里是使用自定义 POST 类型和 ACF 字段获取 WP POST 的解决方案:
SELECT ID, p.post_title as 'Post Title', t.name as 'Category', p.post_date as
"Post Date", p.post_name as "Post Name" , m2.meta_value AS "Prix", m4.meta_value
AS "Surface"
FROM mod803_posts p, mod803_terms t, mod803_term_relationships tr,
mod803_term_taxonomy tx, mod803_postmeta m2, mod803_postmeta m4
WHERE p.post_type = 'stock'
AND p.post_status = 'publish'
AND tx.taxonomy = 'typedestock'
AND p.ID = tr.object_id
AND tr.term_taxonomy_id = t.term_id
AND tx.term_id = t.term_id
AND m2.post_id = p.id AND m2.meta_key = 'Prix de vente'
AND m2.post_id = p.id AND m4.meta_key = 'Surface'
我创建了一个自定义 post 类型:stock
有现货,我用ACF添加了很多自定义字段
我创建了大约 20 个股票。
现在,我正在尝试为每个 post.
获取不同自定义字段(在 workbench 中)的值这里有一些字段:prix(价格)、ville(城市)、nombre de chambres(房间数)
我想要的结果:
post_title | prix | ville | nombre de chambres
Title 1 | 20 | paris | 3
Title 2 | 40 | marseille| 4
Title 3 | 30 | royan| 2
etc...
我试过的代码:
SELECT post_title,
(select meta_value from mod803_postmeta where meta_key = 'prix')
FROM mod803_posts
WHERE post_type='stock' AND post_status='publish'
我得到标题和一个名为“select meta_value 来自 mod803_postmeta 的列,其中 meta_key = 'prix'” 但该列是 'NULL'.
谢谢
因此,这里是使用自定义 POST 类型和 ACF 字段获取 WP POST 的解决方案:
SELECT ID, p.post_title as 'Post Title', t.name as 'Category', p.post_date as
"Post Date", p.post_name as "Post Name" , m2.meta_value AS "Prix", m4.meta_value
AS "Surface"
FROM mod803_posts p, mod803_terms t, mod803_term_relationships tr,
mod803_term_taxonomy tx, mod803_postmeta m2, mod803_postmeta m4
WHERE p.post_type = 'stock'
AND p.post_status = 'publish'
AND tx.taxonomy = 'typedestock'
AND p.ID = tr.object_id
AND tr.term_taxonomy_id = t.term_id
AND tx.term_id = t.term_id
AND m2.post_id = p.id AND m2.meta_key = 'Prix de vente'
AND m2.post_id = p.id AND m4.meta_key = 'Surface'