Variations searching with sku not working even with the function

[ad_1]

one more detail, when I am using live search while typing I am getting the result! So your plugin is working obviously.

But when I press enter key, no results in my search page.

so the problem is somewhere in my theme but I have no idea where to start looking 🙁

this is the sql query from this filter “relevanssi_query_filter”

u034470 is the SKU from the variation

SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 1 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 1 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf FROM wp0m_relevanssi AS relevanssi WHERE relevanssi.term = ‘u034470’ AND relevanssi.doc NOT IN (1693) AND ( relevanssi.doc IN ( SELECT DISTINCT(posts.ID) FROM wp0m_posts AS posts WHERE posts.post_type IN (‘product’) ) ) ORDER BY tf DESC LIMIT 500

Relevanssi seems to be working correctly. You can confirm that with the Relevanssi admin search (Dashboard > Admin search).

Which theme are you using? How is the search results template built? Some themes do the search in a way that involves extra queries, dropping Relevanssi off the loop.

Yes, I confirm that it is working correctly from the admin search. Also from Ajax live search while typing in the front end.

i am using Impreza theme.

the search template is build using grids from the plugin.

212088 is the ID of the parent product. When I query the below sql shouldn’t I receive all the SKUs of the variations? I am not getting any variation sku in the results. Is this a good point to start digging?

SELECT * FROM wp0m_relevanssi WHERE doc = 212088

i added this in my child theme php functions

add_filter(‘relevanssi_content_to_index’, function ($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”; } } } return $content; }, 10, 2);

If the Relevanssi admin search finds the main product with the variation SKU, the indexing is working correctly and there’s no need to debug that.

I have nothing in my records for Impreza, and since it’s a Premium theme, I can’t try it out. But it advertises grid layouts, so if you’re using some kind of an advanced grid layout on the search results page, it’s quite possible the grid layout uses custom queries that don’t work with Relevanssi.

I noticed there’s an UpSolutions themes support ticket for adding Relevanssi support. I can’t access that, but as a customer, you should be able to read it. How has UpSolutions responded to the ticket?

i will search for the answer of upsolutions tomorrow.

regarding the relevanssi_content_to_index filter, when I tried to see what I am getting in your debug screen, I am not getting the variations SKUs. Is this correct in your opinion?

i would expect to get all variations SKUs

Yes, if the filter is working correctly, you should see the variation SKUs in the debugging screen – but if you do not see the variation SKUs in the debugging screen, the search should not work either, so if the search is working, something’s weird.

The filter function seems correct to me.

look, the filter was working on admin search because I had variation post type selected, not because of the filter.

when I removed the product_variation from indexing, and rebuild the indeed, the admin search stopped finding the variation product using sku!

it seems that the php filter is not working as expected.

can you imagine a reason why the additional content is not appended?

Nothing obvious
 Try debugging the function. Does it run in the first place? If it runs, does the get_posts() fetch all the variations? Does the function get the correct SKUs?

Change the function to this and then go save a product with variations:

add_filter( 'relevanssi_content_to_index', function ($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);
var_dump("FOUND " . count( $variations ) . " VARIATIONS");
    if (!empty($variations)) {
      foreach ($variations as $variation) {
        $sku = get_post_meta($variation->ID, '_sku', true);
        $content .= " $sku";
var_dump("VARIATION SKU: $sku");
      }
    }
  }
exit();
  return $content;
}, 10, 2);

What does this print out?

nothing strange!

the product saved successfully and yet no SKU of variations in debug

That is strange! The product shouldn’t save successfully, it should halt and show output. The filter function doesn’t run, that’s why it doesn’t do anything.

If the function doesn’t work in the theme functions.php, you can try using it in a code snippet plugin.

Thank you very much for your help and your time, I will investigate on my own and I will post the solution here.

i found it!!!

for some reason, which i cannot understand I had these lines of code in my child theme.

/* relevanssi search */ add_filter(‘relevanssi_index_content’, ‘__return_false’); add_filter(‘relevanssi_fuzzy_query’, ‘rlv_partial_inside_words’); function rlv_partial_inside_words($query) { return “(term LIKE ‘%#term#%’)”; }

once again I really appreciate the time and effort you spent for me. I will definitely tell my client to purchase your pro version. This professional support is top priority for me!

thank you and have a nice day

closing the ticket as solved

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer