我在WP\\u查询中运行以下参数集。
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'tag\' => $taxonomy,
\'post_type\' => \'initiative\',
\'paged\' => $paged,
\'posts_per_page\' => 9,
\'category_name\' => $category,
\'tag__not_in\' => 15,
\'meta_key\' => \'initative_weight\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\'
);
就这样,它工作得很好,但当我翻阅结果时,我会看到一些重复的内容。现在,如果我去掉分页,只显示所有内容,没有重复。
$args = array(
\'tag\' => $taxonomy,
\'post_type\' => \'initiative\',
\'posts_per_page\' => -1,
\'category_name\' => $category,
\'tag__not_in\' => 15,
\'meta_key\' => \'initative_weight\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\'
);
此外,如果保留分页,但删除orderby,则分页存在,并且没有重复。
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'tag\' => $taxonomy,
\'post_type\' => \'initiative\',
\'paged\' => $paged,
\'posts_per_page\' => 9,
\'category_name\' => $category,
\'tag__not_in\' => 15,
\'post_status\' => \'publish\'
);
那么,我做错了什么?我似乎无法使用分页运行WP\\U查询(&U);按自定义字段排序而不获取重复项。然而,我可以自己做每一件事。我是错过了一步还是遇到了一个bug?
最合适的回答,由SO网友:rmlumley 整理而成
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'tag\' => $taxonomy,
\'post_type\' => \'initiative\',
\'paged\' => $paged,
\'posts_per_page\' => 9,
\'category_name\' => $category,
\'tag__not_in\' => array(15),
\'meta_key\' => \'initative_weight\',
\'orderby\' => array(\'meta_value_num\' => \'DESC\', \'title\' => \'ASC\'),
\'post_status\' => \'publish\'
);
我将tag\\uu not\\u in更改为数组,并将orderby也更新为数组。