您可以使用meta_key
参数,其结果将类似于使用EXISTS
sql语句。
<?php
$users = get_users(array(
\'meta_key\' => \'your_meta_key\',
));
或者,您可以使用空字符串
meta_value
(默认)和
>
对于
meta_compare
. 结果是一样的(可能是因为
meta_value
如果为空,则忽略!)。
<?php
$users = get_users(array(
\'meta_key\' => \'your_meta_key\',
\'meta_value\' => \'\',
\'meta_compare\' => \'>\',
));
第一种方法在使用
WP_Query
和
meta_query
也我的插件示例:
$links = get_posts(array(
\'post_type\' => self::POST_TYPE,
\'numberposts\' => apply_filters(\'seoal_number_links\', -1),
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => self::get_key("type_{$post->post_type}"),
\'value\' => \'on\',
\'compare\' => \'=\'
),
array(
\'key\' => self::get_key(\'url\'),
\'compare\' => \'EXISTS\' // doesn\'t do anything, just a reminder
),
array(
\'key\' => self::get_key(\'keywords\'),
\'compare\' => \'EXISTS\' // doesn\'t do anything, just a reminder
)
),
\'suppress_filters\' => false,
));