How to wordpress search is use to search WP e-Commerce products

Here i solve the problem

Edit your search.php file in your template directory. Put code like bellow

<div>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php ; the_content(”,FALSE,”); ?>
<div></div>
<?php endwhile; ?>
<?php else : ?>

<?php
global $wpdb;
// take search terms (check better use of escape later)
$s = $wpdb->escape(stripslashes($wp_query->query_vars[‘s’]));

//$sql = “SELECT * FROM “.$wpdb->prefix.”product_list WHERE “.$wpdb->prefix.”product_list.name LIKE ‘%”.$s.”%’ OR “.$wpdb->prefix.”product_list.description LIKE ‘%”.$s.”%’”;
$sql = “SELECT * FROM wp_wpsc_product_list Where name LIKE ‘%”.$s.”%’ OR description LIKE ‘%”.$s.”%’ AND active=1 AND publish=1″;

$product_list = $wpdb->get_results($sql,ARRAY_A);

if (!$product_list) {
$output = “<p>Din s&ouml;kning matchade inga produkter.”;
//$output = “<p>There are no products found with the search term <i>”.$s.”</i>.”;
//echo $s;
}
else  {
$output = “<div id=’search_list_products’>\n\r”;
foreach((array)$product_list as $product) {
$output .= “<div class=’search_product’>\n\r”;
$output .= “<a href=’”.wpsc_product_url($product[‘id’]).”‘>”;
if($product[‘image’] != ”) {
//$output .= “<img src=’”.WPSC_THUMBNAIL_URL.$product[‘image’].”‘ title=’”.$product[‘name’].”‘ alt=’”.$product[‘name’].”‘ />\n\r”;
$output .= $product[‘name’].”\n\r”;
//$output .= “<p>\n\r”;
//$output .= stripslashes($product[‘name’]).”<br />”;
// $output .= “<span class=’front_page_price’>\n\r”;
/*if($product[‘special’]==1) {
$output .= “<span class=’oldprice’>”.nzshpcrt_currency_display($product[‘price’], $product[‘notax’]).”</span><br />\n\r”;
$output .= nzshpcrt_currency_display(($product[‘price’] – $product[‘special_price’]), $product[‘notax’],false,$product[‘id’]);
} else {*/
//$output .= “”.nzshpcrt_currency_display($product[‘price’], $product[‘notax’]);
//}
//$output .= “</span>\n\r”;
//$output .= “</p>\n\r”;
}
$output .= “</a>”;
$output .= “</div>\n\r”;
}
$output .= “</div>\n\r”;
$output .= “<br style=’clear: left;’>\n\r”;
} // else

echo $output;

?>
<?php endif; ?>
</div><!– omoss_post_div END –>

(1031)

About Zahidul Hossein Ripon

Zahidul Hossein Ripon a Bangladesh national, born in 1983 did Bachelor of Science in Computer Science and Engineering. At present, Mr. Ripon is working as a Managing Director in Coraltech Solutions. Before working with Coraltech Solutions, he worked in different reputed ICT industries in Bangladesh from year 2007. Mr. Ripon is one of the Associate Member of Bangladesh Computer Society. Mr. Ripon attended couple of Conference and Training, Seminars and events of ICT in Bangladesh and abroad. He is one of the co-author of few number of research publications in international scientific journals and proceedings.

,

No comments yet.

Leave a Reply


*