我试图用特定的meta\\u键排除具有特定meta\\u值的帖子,同时也用不同meta\\u键的meta\\u值对帖子进行排序。
这是我当前的WP\\U查询类代码:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => \'50\',
\'meta_key\' => \'release_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'paged\' => $paged
);
$the_query = new WP_Query($args);
按特定meta\\u值部分进行排序效果很好,但我不确定要添加什么来排除具有特定meta\\u值且具有不同meta\\u键的帖子,而不是用于排序的帖子。
非常感谢您的任何建议/帮助。
I got this working with the code below:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => \'50\',
\'meta_key\' => \'release_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'undetermined_date\',
\'value\' => \'TBA\',
\'compare\' => \'!=\',
\'type\' => \'CHAR\'
)
),
\'paged\' => $paged
);
$the_query = new WP_Query( $args );
我已将自定义字段类型更改为返回true或false的复选框,而不是文本框。如何更改此代码以使用复选框?以下是我尝试过的代码:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => \'50\',
\'meta_key\' => \'release_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'undetermined_date_toggle\',
\'value\' => \'true\',
\'compare\' => \'==\',
\'type\' => \'CHAR\'
)
),
\'paged\' => $paged
);
$the_query = new WP_Query( $args );
最合适的回答,由SO网友:Ravinder Kumar 整理而成
您的代码可能是
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => \'50\',
\'meta_key\' => \'release_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'undetermined_date_toggle\',
\'value\' => \'true\',
)
),
\'paged\' => $paged
);
$the_query = new WP_Query( $args );
此代码仅显示具有
undetermined_date_toggle key==true
或按release\\u date\\u键对复选框进行排序(选中)。
Important Link:
WP_Query
*在meta\\u查询中,参数比较和键入为您的要求,无需传递,它们有其默认值
=
和
CHAR
, 有关更多信息,请阅读WordPress codex for WP\\u Query