我需要做完全相同的事情,并找到一种方法。通过多个连接,您将在每个帖子ID的一行中获得所有meta\\u值:
SELECT
p.ID, p.post_content,
p.post_title,
p.post_excerpt,
pm1.meta_value as author,
pm2.meta_value as publisher,
pm3.meta_value as book_condition
FROM wp_posts p
LEFT JOIN wp_postmeta pm1
ON p.ID = pm1.post_id
AND pm1.meta_key = \'author\'
LEFT JOIN wp_postmeta pm2
ON p.ID = pm2.post_id
AND pm2.meta_key = \'publisher\'
LEFT JOIN wp_postmeta pm3
ON p.ID = pm3.post_id
AND pm3.meta_key = \'book_condition\'
WHERE post_type = \'books\' AND post_status = \'publish\'