WordPress not showing more than 10 posts

I am showing posts by shortcode into posts/pages of WordPress, and want to show an infinite list of posts, but it is showing only 10 posts.

Here is my code; please guide me what is wrong with my query.

$args = array( 'post_type' => 'post', 'cat' => '2', 'meta_key' => 'issue_of_article', 'meta_value' => $issue, 'posts_per_page' => -1, 'orderby' => 'artcle_category', 'order' => 'ASC');
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
     $loop->the_post();
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
endwhile;
}

Related posts

Leave a Reply

6 comments

  1. Just add this in your argument

    'posts_per_page' => -1
    

    then you are done.

    One more thing: you can change the default setting from admin to something other than 10. Go to the WordPress admin – Settings – Reading. There is an option like “Blog pages show at most”. Type there the number of posts you want as the default.

  2. You can decide how many posts to show in the loop:

    <?php wp_reset_query(); ?>
    <?php  
    
        $loop = new WP_Query(
            array(
                'post_type'      => 'resource',
                'order_by'       => 'post_id',
                'order'          => 'ASC',
                'post_status'    => 'publish',
                'posts_per_page' => 100
            )                    
        );
    
    ?>
    
    <?php while ($loop -> have_posts()): $loop -> the_post(); ?>
    
        <h1><?php the_title(); ?></h1>
        <p><?php the_content(); ?></p>
    
    <?php endwhile; ?>
    
    1. At first – post WP questions at WordPress.Stackexchange.com

    2. The good way is to add in functions.php:

      add_action(‘pre_get_posts’,’myfunc’);
      function myfunc($query){
      if ($query->is_main_query() && $query->is_archive){
      $query->set( ‘posts_per_page’, 1000);
      }
      return $query;
      }