• Resolved xCelestialx

    (@samvel45)


    Hello. Thanks for plugin, actually closest one with functional variety for my project needs. The only thing is it dont show results translated with polylang. There is two languages on website` Armenian and English. When I type Armenian letters it shows exact posts, but when try english letters, nothing comes in results. Maybe Im doing something wrong, but ive turned on display results from all languages. Actually I’ve tryed To search on elementor post with S&F, then tryed on search with default elementor search form and search template but nothing shows again. Can you tell anything I can do to fix this. Thanks in advance.
    P.S. If you will need I can make a video, its on closed so cant give a link.

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter xCelestialx

    (@samvel45)

    Of course if that will help ive created custom post type and custom fields. They are indexed by relevanssi but still dont show translated posts when type translated posts info.

    Plugin Author Mikko Saari

    (@msaari)

    Does the Relevanssi Polylang setting (in the searching settings) have any effect? Try turning it on or off. What if you search with the Relevanssi admin search (Dashboard > Admin search), does that work any better?

    Thread Starter xCelestialx

    (@samvel45)

    Thanks for response. Actually Ive tryed both setting on, off and switched on separately but there is no any change. I have even switched to polylang regular version to check if there is any problem with pro version but it was still same issue, also same when i switched to other theme(From hello to astra). Is there anything else I can try?

    Plugin Author Mikko Saari

    (@msaari)

    Did you try the Relevanssi admin search? Does that work?

    Please explain the problem in more detail. Which of these cases work and which don’t?

    a) Site in Armenian, search in Armenian
    b) Site in Armenian, search in English (Polylang set to allow all languages)
    c) Site in English, search in English
    d) Site in English, search in Armenian (Polylang set to allow all languages)

    Are all the posts indexed correctly, both in English and Armenian (you can see that with the Relevanssi debugger)?

    Thread Starter xCelestialx

    (@samvel45)

    Okay i’ll explain in more detailed way. Site works when a) and c) and dont work when b) and d). When I do admin search again it shows nothing from translated posts,both on archive and admin search shows only current language posts. If I type post title on Armenian language archive with english letters it show posts if there is english word included. For example if I type name “Aram” in search it shows all Aram named posts if both page and letters are armenian(it succesfully index even custom fields of post). So when I type with english letters it shows nothing,except situations when there is Aram typed in post with english letters. And the same situation when I type with armenian letters. As I can say there is feeling like relevanssi absolutely dont understand that there is posts and they are connected as translations. Actually maybe I need to synchronize translations? The problem is it will overwrite all existing posts(about 1500+) so I’m scared to try that. Thanks for attention.

    Plugin Author Mikko Saari

    (@msaari)

    Also, what is your expected result here? Do you expect Relevanssi to return the Armenian post when you search for a word that appears in the English version of that post? That’s not going to happen; Relevanssi treats the different language versions as independent posts.

    However, if Relevanssi is set to return all languages in results, searching for an English term should return the English-language post. Relevanssi does this by removing the Polylang language restriction from the search query; it’s possible that does not work if something else overrides it.

    Thread Starter xCelestialx

    (@samvel45)

    Oh now I got that. As professional can you recommend me search add-on that can fit for that capabilities. Thans again.

    Plugin Author Mikko Saari

    (@msaari)

    I don’t know if other plugins do this. Since Relevanssi gives you full control over what gets indexed, you can set Relevanssi up this way. I have never done such a thing, but you can create a filter function that runs on post indexing and, whenever a post is indexed, gets the translation content and includes it in the index for the other post.

    Set up this way, Relevanssi would essentially index the English and Armenian versions with the same content. That way, when you search for English content in the Armenian posts, you’d find the Armenian version of the post.

    add_filter( 'relevanssi_content_to_index', 'rlv_polylang_sync', 10, 2 );
    function rlv_polylang_sync( $content, $post ) {
      $translated_post_id = pll_get_post( $post->ID );
      if ( $translated_post_id ) {
        $translated_post = get_post( $translated_post_id );
        $content        .= ' ' . $translated_post->post_content;
        $content        .= ' ' . $translated_post->post_title;
      }
      return $content;
    }

    Something like this, perhaps. If you add this and rebuild the Relevanssi index, the search should return the translations as you wish, if I’ve understood you correctly. Or it may not; I haven’t tested this, as I don’t have a Polylang setup at the moment.

    Thread Starter xCelestialx

    (@samvel45)

    No, that doesnt make any sense. Ive placed code in custom snippet and child theme functions ,reindexed both time, both time not any result. Actually I have similar projects where this possibility would be a lifesaver. I can ever place website live and give you permissions. If this functionality work it would be a breakthrough for multilingual search.

    Plugin Author Mikko Saari

    (@msaari)

    Ok, I set up a Polylang site and checked the code. It looks like I had it almost right! pll_get_post() defaults to the current language, which isn’t helpful. Here’s a version that worked (replace fi with the Armenian language code):

    add_filter( 'relevanssi_content_to_index', 'rlv_polylang_sync', 10, 2 );
    function rlv_polylang_sync( $content, $post ) {
      $language = pll_current_language() === 'en' ? 'fi' : 'en';
      $translated_post_id = pll_get_post( $post->ID, $language );
      if ( $translated_post_id ) {
        $translated_post = get_post( $translated_post_id );
        $content        .= ' ' . $translated_post->post_content;
        $content        .= ' ' . $translated_post->post_title;
      }
      return $content;
    }
    Thread Starter xCelestialx

    (@samvel45)

    Absolutely brilliant. Yo’ve just made a monster) Thanks For Patience and Help.2 Weeks of suffering ended there…

    Thread Starter xCelestialx

    (@samvel45)

    Hello again. Sorry for bothering you once again. Actually I’ve asked meta box developers is there any value like post_title to index their fields too to add it in like($content .= ‘ ‘ . $translated_post->post_title;) field as you provided before, and they was little confused or didnt got what i’m asking for so they started to give links to faqs and things like that. Because you’ve created compaitibility with MB and relevanssi maybe you know how can I reach that? Big thanks again.

    Plugin Author Mikko Saari

    (@msaari)

    Metabox uses custom fields, and that’s simple to add. To add custom field data from the translated post, use the following:

    $content .= ' ' . get_post_meta( $translated_post_id, 'custom_field_name', true );

    Add one of these lines for each custom field you want to include.

    Thread Starter xCelestialx

    (@samvel45)

    Brilliant once again.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Relevanssi dont show polylang post translations’ is closed to new replies.