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,
hello
(but you can see the Hello World
blog is there on the archive)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 typeThese 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With