我正在尝试构建一个wp\\u查询,到目前为止,我已经使用以下查询获得了所需的结果。
$args = array(
\'meta_query\' => array(
\'relation\' => \'OR\',
array( //check if meta key exists
\'key\' => \'youtube-1\',
\'compare\' => \'=\',
),
array( //or not exists
\'key\' => \'youtube-1\',
\'compare\' => \'NOT EXISTS\'
)
),
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
);
The problem:我想检查所有youtube元键,它们是从foreach循环中提取的数组形式。例如
array(youtube-1, youtube-2, youtube-3, youtube-4 and so on..)
当然,这些职位将由meta_value_num
.
任何小费都将不胜感激。谢谢
SO网友:Owais Alam
WP_Query()自定义字段(即meta)查询可以处理字段值的数组。只需将比较键添加到数组中:
$args = array(
\'numberposts\' => -1,
\'post_type\' => \'post\',
\'meta_query\' => array (
array (
\'key\' => \'my_key\',
\'value\' => \'target_value\',
\'compare\' => \'IN\'
)
) );
$new_query = new WP_Query( $args );