Why am I being limited to ten posts on a custom loop?

For example, I have a link on my site like /tag/green and select content from all posts tagged green are shown using a file loop-tag.php which is about as simple as

<?php
if ( have_posts() ) :  while ( have_posts() ) : the_post();  ?>
<!-- Here I grab the image from the post with that tag -->  
<?php endwhile;  ?>

This works however it is being limited to 10 posts. Why is this being limited to 10 like this?

Related posts

Leave a Reply

1 comment

  1. Because it must be set in back end of your wordpress site.
    You can check and change it from Blog pages show at most field from settings => Reading pages menu. As shown in below screenshot.

    Blog pages show at most

    It will change the setting for all pages , but if you want to make this change only for tag page then in your case you can change the code in loop-tag.php file as following :

    global $wp;
    $s_array = array( 'posts_per_page' => -1 );  // Change to how many posts you want to display 
    $new_query = array_merge( $s_array, (array) $wp->query_vars );
    
    // The Query
    $the_query = new WP_Query( $new_query );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
             ?>
            <!-- Here I grab the image from the post with that tag --> 
            <?php
        }
    
        /* Restore original Post Data */
        wp_reset_postdata();
    }
    

    You can also use pre_get_posts action hook to change post limit.