您的示例有点难以理解,因为它似乎要查询X,Y,Z,AB,ID,IA
. 我希望您仍然能够理解下面发布的代码:
// query posts that have on of the custom values for the custom meta key \'my_key\'
// and/or one of the custom meta values for the meta key \'your_key\'
$posts = get_posts( array(
\'post_type\' => \'my_post_type\'
,\'meta_query\' => array(
array(
\'key\' => \'my_key\'
,\'value\' => array( \'AB\', \'ID\', \'IA\' )
,\'compare\' => \'IN\'
)
,array(
\'key\' => \'your_key\'
,\'value\' => array( \'AB\', \'ID\', \'IA\' )
,\'compare\' => \'IN\'
)
) );
其他比较值为
\'LIKE\', \'NOT LIKE\', \'NOT IN\', \'BETWEEN\', \'NOT BETWEEN\'
如果后两个保留用于数字比较,并且需要额外的元键/值对:
\'type\' => \'numeric\'
.