Search code examples
wordpresssearchpluginspolylang

Wordpress Polylang Strings searchable?


i'm using Polylang with PODS and different custom post types. The Wordpress search is working fine for all of the content inside the posts but what about the strings i have to replace in the template? Are they not searchable at all?

Is there any other way to make the polylang strings in templates searchable for the Wordpress search? The strings in the templates are printed with:

<?php echo pll_e('headlineX'); ?>

The search result however doesn't show anything i put in the string table of polylang.

Is there any other way to translate and make it searchable? Maybe another plugin?

Thanks for your help!


Solution

  • By default WordPress only searches in post_title, post_excerpt, post_content fields so to answer your question - no, your strings translated with pll__()/pll_e() are not searchable.

    Your options:

    • Store all translations in post_meta and modify the WordPress search query to also search for strings in your custom meta key. Technically you should be able to search in Polylang tables too, but it might be complicated and inefficient.
    • This might be overkill, but consider using ElasticPress. You can inject data into the ElasticPress index for your post/pages/cpt's, set search weights for different types of data (e.g. title, content, or your custom meta data). ElasticSearch/ElasticPress will also significantly improve your search accuracy and speed.