我有三张桌子:
当我从wp_posts
我正在使用LEFT JOIN
从wp_metadata
, 但是如何从第三个表中获取值users
?
示例:
我的WordPress博客上有一篇帖子。在那篇文章中,我有一些元字段,其中一个叫做userid
. 我的用户位于WordPress之外的一个表中。如何从表中获取用户的用户名users
post元键userid
等于users
-表格行ID?
下面是我目前的SQL请求:
$result = query("
SELECT ID, post_title, post_excerpt, post_content,
m.meta_value AS placeid,
i.meta_value AS photoid,
r.meta_value AS rating,
u.meta_value AS userid,
b.username
FROM wp_posts p
LEFT JOIN wp_postmeta m ON (m.post_id = p.ID)
LEFT JOIN wp_postmeta i ON (i.post_id = p.ID)
LEFT JOIN wp_postmeta r ON (r.post_id = p.ID)
JOIN wp_postmeta u ON (u.post_id = p.ID)
LEFT JOIN brugere b ON (b.id = userid)
WHERE m.meta_key = \'placeid\'
AND i.meta_key = \'photoid\'
AND r.meta_key = \'rating\'
AND u.meta_key = \'userid\'
AND post_status = \'publish\'
ORDER BY ID DESC
LIMIT 50
");
我想要一个查询,因为我在
print json_encode
.