如何在WordPress中显示所有帖子?

Alp*_*ati 8 wordpress

我想在我的 WordPress 主页中显示所有帖子。

我写了以下查询以获取所有帖子,但我没有收到所有帖子。它只显示 10 或 11 个帖子:

 $args = array(
                'post_type' => 'post',
                'posts_per_page' => $number,
                'order' => $sort_by,
                'orderby' => 'title',
                'post_status' => 'publish',
                'tag' => $tags,
                'ignore_sticky_posts' => 1,
                );
 $args['tax_query'] =  array(
                    array(
                    'taxonomy' => 'post_format',
                    'field' => 'slug',
                    'terms' => 'post-format-video',
                    ));
 $query = new WP_Query($args);
Run Code Online (Sandbox Code Playgroud)

所以请让我知道如何获得所有帖子。

Nar*_*r P 10

显示所有已发布的帖子。您必须使用post_per_page='-1'来检索所有帖子。

$args = array(
'post_type'=> 'post',
'orderby'    => 'ID',
'post_status' => 'publish',
'order'    => 'DESC',
'posts_per_page' => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php the_title(); ?>   
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
Run Code Online (Sandbox Code Playgroud)

希望这会按照您的期望检索所有帖子。