Wordpress:显示一个类别的 25 个帖子和另一个类别的 55 个帖子

Wordpress: displaying 25 posts from one category and 55 from another

我正在尝试创建一个循环,该循环将从一个类别中获取最新的 25 个 post 并从另一个类别中获取最新的 55 个,它们需要在同一个循环中并且 post s 在同位素过滤系统中,当它打开 'all' 时,它需要按日期顺序显示所有类别,而不是类别类型 >post 日期,是否有这样做的技巧?

谢谢,哈利。

编辑: 这是我目前的 get_posts 循环;

            <?php
            global $post;
            $myposts = get_posts('cat=10,11,49&numberposts=50');
            foreach($myposts as $post) :
            setup_postdata($post);
            $cat_name = '';
            $category = get_the_category();
            $cat_name = $category[0]->slug;
            ?>


            <?php endforeach; ?>

我尝试了一些合乎逻辑的事情,例如;

            $myposts = get_posts('cat=10,49&numberposts=50', 'cat=11&numberposts=50');

但这只是从类别 10 和 49 中返回了 posts。

我想也许这样的东西可以工作,但需要正确的语法;

      $myposts11 = get_posts('cat=11&numberposts=50');
      $myposts1049 = get_posts('cat=10,49&numberposts=50');
      $myposts = $myposts1049 + $myposts11;

您所尝试的问题是您将两个 post 数组添加在一起,就好像它们是数字一样;

 $myposts = $myposts1049 + $myposts11;

您应该使用 array_merge 将两个数组合并为一个数组并循环遍历它;

 $myposts = array_merge( $myposts1049, $myposts11 );

编辑

查看 Wordpress StackExchange 站点,Otto 在这里回答了一个非常相似的问题;

https://wordpress.stackexchange.com/questions/130009/how-to-merge-two-queries-together#answer-130055

并且在 WP_Query 对象中使用新数组之前还使用 array_unique 来消除重复项。