WP_QUERY和ORDERBY META_VALUE_NUM显示重复项

时间:2015-09-16 作者:rmlumley

我在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?

1 个回复
最合适的回答,由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也更新为数组。

相关推荐

Show pagination in WP_Query

我正在编写一个foodblog,并试图在特定页面中显示收藏夹帖子列表,但我对分页有一些问题。我在前面的问题中尝试了不同的解决方案,但都没有解决问题。非常感谢 <?php $my_favs = get_user_meta(get_current_user_id(), \'user_favs\', true); $args = array( \'post_type\' => array(\'recipe\', \'post