Searching a custom table in wordpress

admin

Administrator
Staff member
I'm currently building a site for a client and they want a search feature that will search all of the products they supply.

I have created a new table in the database called sc_products and then tried the below code in a wordpress template page but I don't appear to be getting anywhere. If anyone knows how I can get this working that would be awesome!

Code:
<?php
/* 

Template Name: myTemp

*/

function search_it() {
if ( is_search() && isset($_GET['s'])) {

    global $wpdb;

    $address_table = $wpdb->prefix . "sc_products";
    $myrows = $wpdb->get_results( 'SELECT product FROM ' . $sc_products );
    foreach ( $myrows as $single_row ) {
         global $single_row;
    }
    $product = $single_row->product;
}
    return $product;
}
$city = search_it();
echo $city;

get_search_form();

?>