这将为您提供所有没有元键fizzbizz的东西。自定义循环部分,我取消了directly from the codex.
$pageposts = $wpdb->get_results("
SELECT * FROM wp_posts p
LEFT JOIN wp_postmeta m
ON p.ID = m.post_id
WHERE m.meta_key <> \'fizzbizz\'
OR m.metakey IS NULL
ORDER BY p.post_date DESC;
");
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
// now you are in the loop, use the_title() or whatever
这将在有键的地方获取所有内容,但值为“foobar”
$pageposts = $wpdb->get_results("
SELECT * FROM wp_posts p
JOIN wp_postmeta m
ON p.ID = m.post_id
WHERE m.meta_key = \'fizzbizz\'
AND m.meta_value = \'foobar\'
ORDER BY p.post_date DESC;
");
最后一个很棘手,我不太确定。。。
编辑
修复了第一个查询,因为
this question.