这里需要考虑以下几点:
1.)仅当值存在时,才尝试添加元查询:
$pairedThing = get_field(\'myThing\');
$args = [
\'posts_per_page\' => 2,
\'post_type\' => \'thing\',
];
if ( ! empty( $pairedThing ) ) {
$args[\'meta_key\'] = \'identifier\';
$args[\'meta_value\'] = $pairedThing;
}
2.)没有元密钥集的帖子的帐户:
$pairedThing = get_field(\'myThing\');
$args = [
\'posts_per_page\' => 2,
\'post_type\' => \'thing\',
\'meta_query\' => [
\'my_meta_query\' [ // Multiple meta-queries per handle.
\'relation\' => \'OR\',
[
\'key\' => \'identifier\',
\'value\' => $pairedThing,
\'compare\' => \'=\',
],
[
\'key\' => \'identifier\',
\'compare\' => \'NOT EXISTS\',
],
],
]
];