首页 > WordPress学习 > 通过WP_Query()函数查询指定的多个文章ID 展现指定内容

通过WP_Query()函数查询指定的多个文章ID 展现指定内容

时间:2022年12月5日 分类:WordPress学习 浏览量:254

前面有一篇文章是:利用get_posts()函数 调用指定多个ID对应的文章;这篇,我们用WP_Query()函数来实现。

          <?php 
          $myarray = array(14683,14862,14861,14859,14858,14857,14826,14689,14687,14686,14683,14682);
          $args=array(
              'post_type' => 'post',
              'post__in' => $myarray,
              'posts_per_page' => 12,
              'orderby' => 'post_date',
              'order' => 'DESC',
          );
          $newpost = new WP_Query($args);
          if ( $newpost -> have_posts() ): while ( $newpost -> have_posts() ) : $newpost ->the_post(); ?>
              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
          <?php  endwhile; endif; wp_reset_query(); ?>

通过post__in来获取ID数组,再用WP_Query()函数来调用,如此即可将需要指定的文章调用出来。

版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权

文章名称:通过WP_Query()函数查询指定的多个文章ID 展现指定内容

文章链接:https://news.yynnw.com/132.html

该作品系作者结合个人学习经验及互联网相关知识整合。如若侵权请通过投诉通道提交信息,我们将按照规定及时处理。

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签:

最新文章