我正在使用WP Data Tables从 SQL DB 创建一个表。在 wordpress 后端中,要使用的示例代码如下所示:
SELECT post_id, post_date
FROM wp_posts
WHERE post_type = 'custom_post_type'
AND post_status = 'publish'
我试图从帖子元中获取自定义字段值。这是我到目前为止...
SELECT post_id, post_date
FROM wp_posts
WHERE post_type = 'custom_post_type'
AND post_status = 'publish'
AND SELECT custom_field_key_1, custom_field_key_2, custom_field_key_3
FROM wp_postmeta
WHERE post_id = post_id
更新:
我发现需要 p.ID 而不是 post_id 并且我需要搜索 meta_key。就像是...
SELECT p.post_title,
p.post_date,
pm.meta_key = 'custom_field_key'
FROM wp_posts p
INNER JOIN wp_postmeta pm
ON p.ID = pm.post_id
WHERE p.post_type = 'custom_post_type'
AND p.post_status = 'publish'