programing

WordPress에서 모든 게시물을 표시하는 방법

madecode 2023. 3. 14. 22:03
반응형

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);

그래서 어떻게 하면 모든 포스트를 받을 수 있는지 알려주세요.

게시된 모든 게시물을 표시합니다.모든 게시물을 검색하려면 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(); ?>

기대한 대로 모든 게시물이 검색되기를 바랍니다.

여러 루프를 시도합니다.

<?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>    
    <!-- do stuff ... -->
    <?php endwhile; ?>
<?php endif; ?>

Advanced 쿼리가 필요한 경우 다음을 사용합니다.

<?php query_posts( 'post_type=post&posts_per_page=10'); ?>

query_parts()를 사용하여 모든 게시물을 가져올 수 있습니다.

변수 설정posts_per_page => -1

따라서:

 $args = array(
                'post_type' => 'post',
                'posts_per_page' => -1,
                'order' => $sort_by,
                'orderby' => 'title',
                'post_status' => 'publish',
                'tag' => $tags,
                'ignore_sticky_posts' => 1,
              );

그러면 쿼리가 테이블 내의 모든 게시물을 가져옵니다.

자세한 내용은 WP Query 문서를 참조하십시오.

언급URL : https://stackoverflow.com/questions/39047664/how-to-display-all-posts-in-wordpress

반응형