Skip to main contentSkip to footer

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

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Flatsome
Posts and pages on the product search results The Flatsome theme, when combined with WooCommerce, has a product search results…

Related Posts:

Comment Section:

14 Comments. Leave new

  • i need to exclude wpsc-variations from search results…

    Reply
    • What it is? A post type? A taxonomy? A custom field?

      Reply
      • 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!

        Reply
        • How they are defined in WordPress terms?

          Reply
          • 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 );

          • 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.

          • Ciprian Cîmpan
            October 28, 2013 8:48 pm

            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.”

            http://wordpress.org/support/topic/plugin-relevanssi-a-better-search-plugin-relevanssi-exclude-specific-custom-taxonomy

            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 […]”
            http://wordpress.org/support/topic/plugin-relevanssi-a-better-search-feature-request-index-content-filter

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

          • Sorry, no idea how this is done, I’m not that familiar with WPEC.

          • Ciprian Cîmpan
            October 29, 2013 12:15 pm

            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!

          • I’m having the same problem. I’m not familiar with Relevanssi. Where does this need to go?

          • Theme functions.php is the usual place.

  • Hi Mikko,

    I left a message on WordPress.org 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 http://www.visser.com.au/wp-ecommerce/plugins/custom-fields/

    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.

    Reply
  • Nice !
    Anything like this for Woocommerce ?

    Reply

Leave a Reply to Mikko Saari Cancel reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed