• Resolved amybryde

    (@amybryde)


    Hi there!

    I am trying to figure out why my search box just disappeared in the last 2 months. It was working like a charm for over 2 years, but now it has vanished.

    My searchform.php file looks like this:

    <form role="search" method="post" class="searchform" action="https://www.calportaviation.com/search-results/">
        <div><label class="screen-reader-text" for="term">Search for:</label>
            <input type="search" value="" placeholder="Part Number or NSN" name="term" id="term" />
            <input type="submit" id="searchsubmit" value="Search" />
        </div>
    </form>

    And my search-results.php file looks like this:

    <?php
    /* Template Name: Search Results
    */
    get_header();
    ?>
    
    <section id="primary" class="content-area">
    	<main id="main" class="site-main" role="main">
    	
    			<?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%'");
    		
    		if ( ! empty( $query_Parts ) ) : ?>
    
    			<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
    
    			//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>';
    }
    
    echo '</tbody></table>';
    		?>
    
    		<?php else : ?>
    		
    <h2 class="center">P/N: <?php echo $PartNum; ?> Not Found</h2>
    <p class="center">Sorry, it doesn't look like we have Part Number <?php echo $PartNum; ?> 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();

    It has been so long that I have had to work on any coding so I am having trouble trying to figure out where to start to fix it!

    Any help would be greatly appreciated. Thank you!

    -Amy

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Your search-results.php code does not reference any search forum.

    Thread Starter amybryde

    (@amybryde)

    Thank you for your input!

    Are you saying that I need to add something like the following?

    <?php get_search_form( true ); ?>

    If so, where would I need to insert that?

    Thanks again for your help!

    Thread Starter amybryde

    (@amybryde)

    I have found the problem and thought it would be worthy to share.

    During one of the updates, a setting was changed in the search widget and it defaulted back to “Show if…Page is…Search Results”. I changed the “Search Results” back to “Front page” as that is where my search box appears on our site.

    Simple fix and all is back to normal!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Part Search Box just disappeared’ is closed to new replies.