• I’ve been tearing my few remaining hairs out over this for days now.

    the site has two languages, controlled by Polylang 2.0.x: english (en) and german (de). English is defined as the default language.

    Posts and Pages are translated, but the two custom post types “Member” and “Events” are set to not being translated in Polylang. This was changed a while back, which is why there are ~50 “member” posts where there are Polylang metadata, and ~40 “member” posts without polylang metadata (object_id and term_taxonomy_id in wp_term_relationships table and term_taxonomy_id in wp_term_taxonomy table).

    This means that the posts without polylang metadata have no default language defined (taxonomy language, eg a:3:{s:6:"locale";s:5:"en_US";s:3:"rtl";i:0;s:9:"flag_code";s:2:"us";}).

    Because WordPress search was unable to find any post that has no polylang metadata, I added `function my_alter_query($query) {

    if ( is_admin() || !$query->is_main_query())
    return;

    if (is_search()){
    $query->set(‘lang’, NULL);
    }

    }
    add_action(‘pre_get_posts’,’my_alter_query’);` to my functions.php.

    This resulted in that “member” posts without polylang metadata only show up in the non-default/preferred language search result: searching in english (default polylang language for the site) gives “no content matched your criteria”, whereas when searching in german the post is found.

    Is there a way to either
    – display search results no matter the language setting of a post?
    and
    – add a default language to posts without turning polylang on?

    Thanks in advance for any hint!

    https://wordpress.org/plugins/polylang/

  • The topic ‘Non-translated Custom Post Types –> strange search results’ is closed to new replies.