Reputation: 11
Novice programmer here. Thanks for any help...
I am working with wp-ecommerce plugin for wordpress:
I would like to be able to search for product tags.
I know wordpress search does not automatically search for tags associated with a blog post. For some reason, the wp-ecommerce search widget does not work. Even if it did, it still does not search for product tags... to my knowledge.
Here is my current custom search.php code:
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php if (is_type_page()) continue; ?>
<div id="cat-products-container">
<h1><?php printf( __( 'Search Results for "%s"', 'kandice' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
<div id="cat-products-internal-container">
<ul class="block">
<?php $i=1 ?>
<?php while (have_posts()) : the_post(); ?>
<?php
if (is_int($i/4)){
echo '<li class="right">';
} else {
echo '<li>';
}
?>
<a href="<?php echo wpsc_the_product_permalink(); ?>">
<img style="width:<?php echo get_option('product_image_width'); ?>px;height:<?php echo get_option('product_image_height'); ?>px" class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>" />
<div class="animated-product-info-container">
<h2><a href="<?php echo wpsc_the_product_permalink(); ?>" title="<?php echo wpsc_the_product_title(); ?>"><?php echo wpsc_the_product_title(); ?></a></h2>
<div class="description-container">
<p><?php echo wpsc_the_product_description(); ?><a class="details-links" href="<?php echo wpsc_the_product_permalink(); ?>"></a></p>
</div><!--description-container-->
</div><!--animated-product-info-container-->
</a>
</li>
<?php $i++ ?>
<?php endwhile; ?>
</ul>
<div class="clear"></div>
<?php else : ?>
<h2 class="no-search-results">No search results found.</h2>
<?php endif; ?>
</div> <!--close cat-products-internal-container-->
</div> <!--close cat-products-container-->
Thanks again!
Upvotes: 0
Views: 3504
Reputation: 420
Though I'm not using the WP-e-Commerce cart plugin (not anymore, anyway), I am have the same problem going on with the WooCommerce cart plugin.. The base issue here is that 'product_tag' (apparently it's the same term title in WooCommerce as it is in WP-eCommerce) is a custom taxonomy term, not a standard post tag. I found a solution in this other StackOverflow thread about the matter:
How to amend wordpress search so it queries taxonomy terms and category terms?
The code example by tkelly worked for me when replacing the term author
in his example with product_tag
as per our needs for the cart plugins.
Upvotes: 1
Reputation: 39892
See the WP_Query reference. You can query on tags.
http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
//return for one tag
$query = new WP_Query( 'tag=cooking' );
//return for multiple tags
$query = new WP_Query( 'tag=bread,baking' );
There are more example in the codex.
Upvotes: 1