【问题标题】:Adding Category Argument into an Array for WordPress Query将类别参数添加到 WordPress 查询的数组中
【发布时间】:2013-02-13 09:58:24
【问题描述】:

我是自定义 WordPress 的新手,我希望查询某个类别中的一系列帖子。我有一个显示该站点所有帖子的数组:

$arguments = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'paged' => $paged,
            'showposts' => $postcount
        );

基本上,我希望能够显示仅属于“营养”类别的所有帖子的数组。我认为这是一个将添加到此数组中的“类别”参数?

【问题讨论】:

    标签: php arrays wordpress


    【解决方案1】:

    参数是category_name 而不是category

    你可以这样做:

        $arguments = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'paged' => $paged,
            'showposts' => $postcount,
            'category_name' => 'Nutrition'
        );
    

    【讨论】:

      【解决方案2】:

      在你的论点中添加category_name

      $arguments = array(
              'post_type' => 'post',
              'post_status' => 'publish',
              'paged' => $paged,
              'showposts' => $postcount
              'category_name' = 'Nutrition'
          );
      
      query_post($arguments);
      

      更多详情请阅读this

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-30
        • 2019-03-03
        • 1970-01-01
        • 2022-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多