Skip to main content
2 of 2
added 114 characters in body
Devon
  • 35
  • 6

Adjust the results quantity for Search Results page pagination

I'm trying to override the number of posts to show on pagination for my search.php template, to be 16 vs 4. In the Reading settings on the back end, it is set to 4, which is desired because my front page uses the same code to display the 4 most recent posts.

Is there a way to designate this on the search.php template page?

This is my template page for Search.php

<?php 
    get_header();
    global $wp_query;
?>

<picture class="featured-image block  pos-rel">
    <div class="t-con flex row pos-abs">
        <h1  class="post-title f-center" title="<?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For', 'locale' ); ?>: <?php the_search_query(); ?>"><?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"</h1> <!--Edit these values to adjust page being shown.-->
    </div>
    <?php echo  get_the_post_thumbnail($page=2, 'full', array( 
        'class' => 'featured'
    )); ?>
</picture>

<section class="main bg-darkpurple">
<div>
    <div class="grid row posts">
        <?php while ( have_posts() ) : the_post(); ?>
        <div class="col">
            <div class="date-container">
                <p class="post-date bg-darkpurple">
                    <?php 
                        $u_time = get_the_time('U');
                        $u_modified_time = get_the_modified_time('U');
                            if ($u_modified_time >= $u_time + 86400) {
                        echo "Last updated ";
                            the_modified_time('F jS, Y');
                        echo ""; }
                        else {echo "Posted "; the_time('F jS, Y');}
                    ?>
                </p>
            </div>
            <?php
                $primary_cat = get_post_meta($post->ID , '_category_permalink', true);
                    if ( $primary_cat != null ) {
                        $cat_id = $primary_cat['category'];
                        $category = get_category($cat_id);
                    } else {
                        $categories = get_the_category();
                        $category = $categories[0];
                    }
                        $category_link = get_category_link($category);
                        $category_name = $category->name;  
                ?>
                    
                <picture class="post-thumb block">
                        
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a>
                    <div class="cat-container">
                        <a class="post-cat bg-darkpurple" href="<?php echo $category_link ?>"><?php echo $category_name ?></a>
                    </div>
                        
                </picture>
                    
                <h3>
                    <a href="<?php the_permalink(); ?>">
                        <?php the_title(); ?>
                    </a>
                </h3>
                    <p><?php echo substr(get_the_excerpt(), 0,160); ?></p>
        </div>
        <?php endwhile; ?>
    </div>
        <div class="pagination flex row f-center">
            <?php 
                echo paginate_links( array(
                    'end_size'     => 2,
                    'mid_size'     => 1,
                    'prev_text'    => sprintf( '<i></i> %1$s', __( 'Other results', 'text-domain' ) ),
                    'next_text'    => sprintf( '%1$s <i></i>', __( 'Other results', 'text-domain' ) ),
                ) );
            ?>
        </div>
    <?php wp_reset_postdata(); ?>
</div>
</section>

<?php get_footer(); ?>

I know this line of code should be what I need, but I'm not sure WHERE to put it:

'posts_per_page' => 16

Thanks for any help!

Devon
  • 35
  • 6