Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 -

Supporter timezone: Europe/Zagreb (GMT+02:00)

Tagged: 

This topic contains 3 replies, has 0 voices.

Last updated by Dražen 15 hours, 30 minutes ago.

Assisted by: Dražen.

Author Posts
May 2, 2025 at 2:52 pm #16989935

evgenyV-2

Background of the issue:
I am using Elementor, ACF, and WPML for a multilingual website. I have a custom post type called 'officials' connected to product categories. These officials are salespeople responsible for specific product categories. On category pages, I display these salespeople using an Elementor loop with a custom filter. In the main language (Hebrew), it works well, but in the English version, the query to retrieve connected salespeople returns empty. I attempted debugging, but the query still returns nothing. The code snippet I used is:
...
elseif (is_product_category()) {
$term_id = get_queried_object_id();

$original_id = apply_filters('wpml_object_id', $term_id, 'product_cat', true, wpml_get_default_language());

$query->set('meta_query', array(
array(
'key' => 'connected_categories',
'value' => '"' .$original_id . '"',
'compare' => 'LIKE'
)
));
}
..

Symptoms:
The query to retrieve connected salespeople in the English version of the site returns empty, despite the connection being visually set in the admin.

Questions:
What am I doing wrong with the query in the English version?
Why does the query return empty for the English version but works in the main language?

May 6, 2025 at 8:28 am #17000086

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

Thanks for contacting us.

As I can see from shared code you are getting original ID, while you should get translated ID of category. And then get translated post related to that translated category.

Please check:

- https://wpml.org/wpml-hook/wpml_object_id/

For example:

elseif (is_product_category()) {
    $term_id = get_queried_object_id();
    
    // Get translated ID in the current language instead of default
    $translated_id = apply_filters('wpml_object_id', $term_id, 'product_cat', false, ICL_LANGUAGE_CODE);
    
    $query->set('meta_query', array(
        array(
            'key' => 'connected_categories',
            'value' => '"' . $translated_id . '"',
            'compare' => 'LIKE'
        )
    ));
}

Let me know how it goes.

Regards,
Drazen

May 6, 2025 at 8:35 pm #17003540

evgenyV-2

Hi Drazen

Thank you for answering. I tried both. The problem is that the function doesn't show any connections when in a translated language, as if they do not exist. I solved the problem by removing the connections between the original "officials" and their translations. Once I did this, everything started working as expected. It is obviously not the best solution, but it works.
Best,
Evgeny

May 7, 2025 at 6:26 am #17004369

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello Evgeny,

Glad to hear you found a workaround.

If you need further help and want us to check further, please create a staging site, and minimize your custom code, best would be WP default theme, Elementor, ACF and WPML plugins active.

Let me know.

Regards,
Drazen