• Last week I activated the plugin, turned on _sku, clicked on the indexing options, where the variations were included. Everything worked great. There have been no WP or plugin updates since then. Today I added product tags to the indexing and since then it can’t find any variant according to the code.

    I tried turning off the variation selection, made a new index, returned the variation selection and the new index. It didn’t help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    1. Check a product variation with the Relevanssi debugger (Settings > Relevanssi > Debugging). Is it indexed correctly?
    2. Try searching for a variation with the Relevanssi admin search (Dashboard > Admin search). Can you find one?
    3. Is your main search restricted to the product post type?
    Thread Starter Milan

    (@milanxy)

    I’m sorry. You were faster and I didn’t have time to correct the text. Searching for the Name and SKU of the variant does not work. I have _sku set and I haven’t changed it.

    1. I don’t have a “product ID”.
    2. It finds everything in “admin search”.
    3. WooCommerce products – selected post, page, product, product_variation, product_tag
    Plugin Author Mikko Saari

    (@msaari)

    A vast majority of WooCommerce themes sets the post_type parameter to product. That makes sense, because product_variation is an internal post type and is not meant for public access in WooCommerce. In general, this method is the preferred way to access variations by SKU.

    Thread Starter Milan

    (@milanxy)

    The PHP code method will not cause a problem with the settings in the plugin (_sku)? Or should I turn it off?

    Plugin Author Mikko Saari

    (@msaari)

    You still need the setting for the main product SKU. The function just adds the variation SKUs for the main product so that you can find the product by searching for a variation SKU. Both are necessary.

    Thread Starter Milan

    (@milanxy)

    Searching by SKU now also finds the variant code, but not the name. It’s not so terrible for me. I mainly needed the SKU. THX
    It’s strange that before it worked without additional PHP code.

    Plugin Author Mikko Saari

    (@msaari)

    You can modify the function so that it also adds the variation name, that’s not a big deal. Change the function to:

    add_filter( 'relevanssi_content_to_index', 'rlv_index_variation_skus', 10, 2 );
    function rlv_index_variation_skus( $content, $post ) {
    if ( 'product' === $post->post_type ) {
    $args = array(
    'post_parent' => $post->ID,
    'post_type' => 'product_variation',
    'posts_per_page' => -1
    );
    $variations = get_posts( $args );
    if ( ! empty( $variations ) ) {
    foreach ( $variations as $variation ) {
    $sku = get_post_meta( $variation->ID, '_sku', true );
    $content .= " $sku {$variation->post_title}";
    }
    }
    }
    return $content;
    }

    I think what changed is a post type restriction in the search. If there’s no post type restriction in the search, Relevanssi will happily return the variations. Relevanssi doesn’t have any problems with them. Your theme does.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.