Customizing content when Search Results come up empty
-
Hi there,
I recently noticed that our search results page is blank when a Part Number is searched that we do not have in stock. I would like to add some content when a search comes up empty. Currently, what I have coded in my custom search-results.php file is not working. Anybody have any ideas? The following is what I have in my search-results.php file:
<?php /* Template Name: Search Results */ get_header(); ?> <section id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <header class="page-header"> <h1 class="page-title"><?php printf(__( 'Search Results for: %s', 'catalog-me' ), '<span>' . $_POST['term'] . '</span>' ); ?></h1> </header><!-- .page-header --> <?php global $wpdb; $PartNum = $_POST['term']; $PartNum = sanitize_text_field( $_POST['term'] ); update_post_meta( $post->ID, 'term', $PartNum ); $query_Parts = $wpdb->get_results( "SELECT * FROM parts WHERE parts.PartNumber LIKE '%$PartNum%' or parts.nsn LIKE '%$PartNum%'"); //echo "<pre>"; print_r($query_Parts); echo "</pre>"; echo '<table class="results"><thead><tr><th>Part Number</th><th>NSN</th><th>Alternate Part Number</th><th>Description</th><th>Condition</th><th>Quantity</th></tr></thead><tbody>'; foreach($query_Parts as $row) { echo '<tr>'; echo "<td>{$row->PartNumber}</td>"; echo "<td>{$row->nsn}</td>"; echo "<td>{$row->nsn2}</td>"; echo "<td>{$row->Description}</td>"; echo "<td>{$row->Condition}</td>"; echo "<td>{$row->CVQuantity}</td>"; echo '</tr>'; } setup_postdata( $post ); echo '</tbody></table>'; ?> </h2> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, it doesn't look like we have that Part Number in our Inventory database. Try a new search with Alternate Part Number or NSN.</p> <?php endif; ?> </main><!-- #main --> </section><!-- #primary --> </div> <?php get_footer();
Any help would be greatly appreciated. Thank you!
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Customizing content when Search Results come up empty’ is closed to new replies.