How to show unlimited posts for default post in WordPress?

I am trying to develop a WordPress blog. I want the blog will show unlimited posts in one page. Posts will come from the default post item. I have used the following loop for that.

<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>
        <?php the_title();?>
        <?php the_content();?>
    <?php endwhile; ?>    

<?php endif; ?> 

But how can I set here -1 value for unlimited posts. Also -1 value not support in admin Reading Settings option. Please tell me the solution.

Related posts

Leave a Reply

4 comments

  1. I would suggest you to do it with an Template file and write some custom query to display all post in one page:

    like this:

    Create a Template file

    <?php
    /* Template Name: All post
    */
    
    $args = array( 'post_type' => 'post', 'posts_per_page' => -1)
    $allpost = get_posts( $args );
    foreach ( $allpost as $post ) {
            setup_postdata( $post );
            the_title();
            the_content();
        }
        wp_reset_postdata();
    ?>
    

    Now in admin select this template file to any page you want to display all post …

  2. May this will help you, by overriding global $wp_query

    <?php global $wp_query ;
        $args = array('post_per_page' => '-1');
        $wp_query = new WP_Query($args) ; // overriding default global of WordPress
    ?>          
    
    <?php if(have_posts()) : ?>
           <?php while (have_posts()) : the_post(); ?>
                    <?php the_title();?>
                    <?php the_content();?>
            <?php endwhile; ?>    
    <?php endif; ?> 
    <?php wp_reset_postdata();  // Don't forget to add this
    ?>
    
  3. I have found the solution .

     $my_args = array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'paged' => $paged
    );
    
    $my_query = new WP_Query( $my_args );
    
    
    if($my_query->have_posts()) : ?>
    <?php while ($my_query->have_posts() ) :  $my_query->the_post(); ?>
    
    <?php the_title();?>
                <?php the_content();?>
        <?php endwhile; ?>    
    <?php endif; ?>