在结尾处我想显示结果的标题,其中 extra1 为meta_key, test 为meta_value。
我的目标是:
非常感谢。
答案 0 :(得分:0)
这是假设您正在处理wordpress database schema的查询:
SELECT post_title
FROM wp_posts
WHERE ID IN
(
SELECT DISTINCT post_id
FROM wp_postmeta
WHERE meta_key = 'extra1' AND meta_value = 'test'
)
Mairy评论后第二次查询:
SELECT post_title
FROM wp_posts
WHERE ID IN
(
SELECT DISTINCT post_id
FROM wp_postmeta
WHERE meta_key IN('extra1','extra2','extra3') AND meta_value IN('test','test1','test2','test3')
)
然后你只需要用php循环结果集,然后根据需要打印帖子标题:
//connect to DB then ($query contains the query above)
$res = mysql_query($query, $db);
while($row=mysql_fetch_array($res))
{
echo($row['post_title']);
}