0

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!

2
  • Be nice, he is new. Tell him why you downvoted! Try and reinclude your question and point people exactly to the problem. For example, How can I make my query filter on tags?
    – mrtsherman
    Aug 16, 2011 at 21:13
  • Thank you sherman for leading me in the right direction. Aug 17, 2011 at 4:12

2 Answers 2

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.