如果手动运行此查询,应该会得到如下响应
(1054,“where子句”中的未知列“wp\\u postmeta.meta\\u key”)
长话短说,wp_postmeta.meta_key
不是的有效列wp_posts
. 你需要JOIN
Posteta表可以使用其列。(有很多资源可以解释JOIN
, 一个是this answer.)
$query = $wpdb->prepare(
"
SELECT p.ID
FROM {$wpdb->posts} AS p
INNER JOIN {$wpdb->postmeta} AS pm
ON p.ID = pm.post_id AND pm.meta_key = %s
WHERE p.ID > %d
AND p.post_type = %s
AND pm.meta_value = %s
ORDER BY p.ID DESC
LIMIT 0, 1
",
\'rid\',
$last_id,
\'room\',
$rid
);