你可以使用NOT EXISTS
作为comparem的值,如果相关,还可以检查空值
此代码仅检查以下情况hidden
元不存在
$postsForSitemap = get_posts([
\'numberposts\' => -1,
\'orderby\' => \'modified\',
\'post_type\' => [\'post\', \'page\'],
\'order\' => \'DESC\',
\'meta_key\' => \'hidden\',
\'meta_compare\' => \'NOT EXISTS\'
];
此检查为
hidden
meta不存在或没有值
$postsForSitemap = get_posts([
\'numberposts\' => -1,
\'orderby\' => \'modified\',
\'post_type\' => [\'post\', \'page\'],
\'order\' => \'DESC\',
\'meta_query\' => [
\'relation\' => \'OR\',
[
\'key\' => \'hidden\',
\'compare\' => \'NOT EXISTS\',
],
[
\'key\' => \'hidden\',
\'value\' => \'\'
]
]
];