Posted on

WP e-Commerce

WP e-Commerce is a popular shopping cart plugin for WordPress. This code by Alexander Gieg, added to functions.php for example, makes Relevanssi work better with WP e-Commerce.

add_filter( 'relevanssi_excerpt_content', 'wpsc_product_excerpt', 10, 3 );
function wpsc_product_excerpt( $content, $post, $query ) {
	if ( 'wpsc-product' === relevanssi_get_post_type( $post->ID ) ) {
		$content = $post->post_content . ( ! empty( $post->post_excerpt ) ? " $post->post_excerpt" : '' );
		if ( 'on' === get_option( 'relevanssi_expand_shortcodes' ) ) {
			$content = do_shortcode( $content );
		} else {
			$content = strip_shortcodes( $content );
	return $content;

Source: WP e-Commerce support in Relevanssi

14 comments WP e-Commerce

  1. Hi Mikko,

    I left a message on about this too and I hope you might be able to help? This solution has helped some, but I am using Visser Lab’s Custom Fields plugin which adds some really nice functionality to WPeC.

    I was hoping you might have a look at extending the above to include that plugin as well?

    Here is the link to Custom Fields for WPec

    The search in WPeC is horrific to say the least especially when you need to search for something like an author.

    If you can help, that would be great.

      1. Well wpsc-variations are products, but they are variations of the same product. Example a shirt – the variations will be the same shirt but yellow, green, blue… the variations does not have its own page, so when its listed on search, it has a broken link. Thats what wpsc-variation is about.
        Thanks for the reply!

          1. Taxonomy! (i guess)

            register_taxonomy( ‘wpsc_product_category’, ‘wpsc-product’, $args );
            $labels = array(
            ‘name’ => _x( ‘Variations’ , ‘taxonomy general name’ , ‘wpsc’ ),
            ‘singular_name’ => _x( ‘Variation’ , ‘taxonomy singular name’, ‘wpsc’ ),
            ‘search_items’ => __( ‘Search Variations’ , ‘wpsc’ ),
            ‘all_items’ => __( ‘All Variations’ , ‘wpsc’ ),
            ‘parent_item’ => __( ‘Parent Variation’ , ‘wpsc’ ),
            ‘parent_item_colon’ => __( ‘Parent Variations:’, ‘wpsc’ ),
            ‘edit_item’ => __( ‘Edit Variation’ , ‘wpsc’ ),
            ‘update_item’ => __( ‘Update Variation’ , ‘wpsc’ ),
            ‘add_new_item’ => __( ‘Add New Variation’ , ‘wpsc’ ),
            ‘new_item_name’ => __( ‘New Variation Name’, ‘wpsc’ ),
            $args = array(
            ‘hierarchical’ => true,
            ‘query_var’ => ‘variations’,
            ‘rewrite’ => false,
            ‘public’ => true,
            ‘labels’ => $labels
            $args = apply_filters( ‘wpsc_register_taxonomies_product_variation_args’, $args );
            // Product Variations, is internally heirarchical, externally, two separate types of items, one containing the other
            register_taxonomy( ‘wpsc-variation’, ‘wpsc-product’, $args );

          2. Hmm… if you’re using non-Premium, it should not index taxonomy terms in the first place, so I’m not quite sure what’s going on here.

          3. Hi there,

            I have the same problem. I already excluded the “variation” taxonomy from WP-E-Commerce, but the plugin still indexes the same post three times, once for the main post and then for each of the two variations attached.

            Some people said there’s a fix for it, but i don’t understand how their solutions work:

            Solution #1: “I managed to get a working solution yesterday which was quite simple.

            $permalink = get_permalink($post->post_parent);

            I then do a check to see if $permalink = 0, if it does i use the_permalink(), otherwise i output $permalink.”


            Solution #2: “That’s because WPEC has products (let’s say, “shirt”), which are a custom post type, as well as variations of a product (for example, “white”, “red”, “big”, “small” etc.), each of which is itself a custom post too, but which shouldn’t be accessed directly. So, while the relevanssi_post_ok filter allows me to make sure those variations don’t appear in the search results […]”

            Can you please point me in the right direction? Thank you!

          4. I managed to fix that by using the relevanssi_post_ok filter, as someone suggested before:

            add_filter(‘relevanssi_post_ok’, ‘relevanssi_default_post_ok_v2’,9,2);
            function relevanssi_default_post_ok_v2($post_ok, $doc) {
            $post = get_post($doc);
            if ($post->post_parent != 0) {
            $post_ok = false;
            return $post_ok;

            Thanks for your plugin – it’s doing a great job and i totally love it!

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *