Search code examples
phpwordpresswoocommercewordpress-themingwoocommerce-theming

Wordpress Search Bar Result a Blank White Page


I have a simple search form on my blog sidebar which will search only the blogs.

<form action="<?php echo get_site_url() ?>" method="GET">
   <input type="search" name="s" placeholder="Click to Search" class="fld-search" required/>
   <input type="hidden" name="post_type" value="post">
   <button class="btn-search"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>

This is the website url : http://dev.wonder.lk/blog/

Following are the search types that I applied,

  1. Value that available in blog - For some values it gives the result, but sometimes it says not found. Ex : Search hello (but you can see the Hello World blog is there on the archive)
  2. Search someother post_type values - Result is a blank white page, even I can't see the header or footer. Ex : Search ninja It's a product type

These are the codes,

search.php

<?php
while ( have_posts() ) : the_post();
   if(isset($_GET['post_type'])) {
           $type = $_GET['post_type'];
           if($type == 'product') {
              get_template_part( 'woocommerce/archive', 'product' ); //working fine
           } else {
              get_template_part( 'framework/template-parts/page/search', 'post' );
           }
   } else {
           get_template_part( 'framework/template-parts/page/search', 'post' );
   }
   endwhile;
?>

search-post.php

<?php

get_header();

//Page Title Bar
$pageTitle = 'Search results for: "'.get_search_query().'"';
echo page_title_bar( $pageTitle, get_template_directory_uri().'/framework/assets/images/pg-title-bar.jpg');
?>

<div class="container blog-wrapper page-container">
    <div class="row">
        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <?php
                    // Include Blog Posts List
                    get_template_part('framework/template-parts/post/blog', 'post-list');
                ?>

            <?php endwhile; ?>

            <div class="pagination-wrapper">
                <?php pagination(); ?>
            </div>

            <?php else: ?>
                <h3>No results found for: '<?php echo get_search_query(); ?>'</h3>
            <?php endif; ?>
        </div>

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
            <?php
                // Include Blog Sidebar
                get_template_part('framework/template-parts/post/blog', 'sidebar');
            ?>
        </div>
    </div>
</div>


<?php get_footer(); ?>

blog-sidebar and blog-post-list are the HTML structure.

Ask me if you want more details.


Solution

  • It worked fine after updating the search.php as following,

    <?php
    
    get_header();
    
    //Page Title Bar
    $pageTitle = 'Search results for: "'.get_search_query().'"';
    echo page_title_bar( $pageTitle, get_template_directory_uri().'/framework/assets/images/pg-title-bar.jpg');
    ?>
    
    <div class="container blog-wrapper page-container">
        <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
                    <?php
                        // Include Blog Posts List
                        get_template_part('framework/template-parts/post/blog', 'post-list');
                    ?>
    
                <?php endwhile; ?>
    
                <div class="pagination-wrapper">
                    <?php pagination(); ?>
                </div>
    
                <?php else: ?>
                    <h3>No results found for: '<?php echo get_search_query(); ?>'</h3>
                <?php endif; ?>
            </div>
    
            <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
                <?php
                    // Include Blog Sidebar
                    get_template_part('framework/template-parts/post/blog', 'sidebar');
                ?>
            </div>
        </div>
    </div>
    
    
    <?php get_footer(); ?>
    

    If I get a reasonable and well described answer I can offer the bounty for that answer.