'pagination not showing in result page search wordpress

I have a problem the search.php pagination page doesn't appear,i tried to use custom pagination.. you can see the pagination does not appear in the screenshot below :

pagination not showing

I really appreciate if you can help me, thank you very much

this is my custom pagination functions.php

<?php
function custom_pagination($pages = '', $range = 2)
{  
 $showitems = ($range * 2)+1;  

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
     global $wp_query;
     $pages = $wp_query->max_num_pages;
     if(!$pages)
     {
         $pages = 1;
     }
 }   

 if(1 != $pages)
 {
     echo "<div class='pagination'>";
     if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
     if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

     for ($i=1; $i <= $pages; $i++)
     {
         if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
         {
             echo ($paged == $i)? "<a class='active'>".$i."</a>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
         }
     }

     if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
     if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
     echo "</div>\n";
    }
 }

function searchfilter($query)
{
    if ($query->is_search && !is_admin()) {
        $query->set("post_type", ["post"]);
    }

    return $query;
}

add_filter("pre_get_posts", "searchfilter");

and this page search.php

<?php
  /**
   * The main template file
   *
   * This is the most generic template file in a WordPress theme
   * and one of the two required files for a theme (the other being style.css).
   * It is used to display a page when nothing more specific matches a query.
   * E.g., it puts together the home page when no home.php file exists.
   *
   * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
   *
   * @package WordPress
   * @subpackage 
   * @since 1.0.0
   */
  get_header();
  ?>
<?php if ( have_posts() ) : ?>
<div class="container">
  <section class="tray ">
    <div class="tray-title">
      <h1 class="section-heading"><span class="h-text"><?php printf( __( 'Search Results For : %s', 'shape' ), '<i>' . get_search_query() . '</i>' ); ?></span></h1>
    </div>
    <div class="tray-content">
      <?php
        // display search result
        $s = get_search_query();
        $args = array(
            'post_type' => 'post',
            's' => $s,
            'posts_per_page' => 1,
            'paged' => get_query_var('paged') ? get_query_var('paged') : 1
        );
        
        $my_query = new WP_Query($args);
        
        // the loop
        if ($my_query->have_posts()):
            while ($my_query->have_posts()):
                $my_query->the_post();
                // display article
                get_template_part('template-parts/content', get_post_format());
            endwhile;
        endif;
        
        wp_reset_postdata();
        ?>
    </div>
    <div style="margin-top:14px; margin-bottom:15px;width: 97%; margin-left: 18px;">
      <!-- Ads -->
    </div>
    <?php if (($my_query->max_num_pages) > 1) { ?>
    <div class="center">
      <?php custom_pagination(); ?>
    </div>
    <?php } ?>
  </section>
</div>
<?php else : ?>
<?php get_template_part( 'no-result'); ?>
<?php endif; ?>
<?php 
get_footer();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source