我认为你在这里做得不对。为什么不使用WP\\u查询?它会以任何你想要的方式给你发帖子,从返回的帖子中你可以得到你的元值。
$params = array(
    \'post_type\' => \'your post type\',
    \'post_status\' => \'publish\',
    \'posts_per_page\' => 10,
    \'meta_key\' => \'your key\',
    \'meta_value\' => \' \',
    \'meta_compare\' => \'!=\',
    \'ignore_sticky_posts\' => 1,
    \'orderby\' => \'meta_value\',
    \'order\' => \'ASC\'
);
$new_query = new WP_Query($params);
 像这样的过滤应该会立即为您提供所有使用meta\\u键的帖子。希望这有帮助!
*更新时间:Here 是codex本身中使用多个自定义字段进行查询的示例。除非有数百个字段,否则这种方法应该非常有效。此外,如果您正在编写SQL查询,则必须对其进行优化,以使其不会成为性能瓶颈。