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.

This topic contains 5 replies, has 3 voices.

Last updated by Diego Pereira 1 year ago.

Assigned support staff: Diego Pereira.

Author Posts
September 21, 2018 at 5:11 pm

Marc

I am trying to:

List events excluding an event-category term.

'tax_query' => array(
array(
'taxonomy' => 'event-category',
'field' => 'term_id',
'terms' => array(103, 318, 317), // exclude exhibitions
'operator' => 'NOT IN'
)
),

Link to a page where the issue can be seen:
hidden link

I expected to see:
no posts in with event-category "exhibition" or "exposicion".

Instead, I got: (see image)

Instead, it works ok with the default language, AND it works ok for all languages if the operator is "IN".
I tried all sort of combinations inside the tax_query, but no luck.

September 21, 2018 at 5:13 pm #2756105

Marc

I am hiding undesired posts for the time being, so you will not see the error in the front page although the error in the query persists.

September 24, 2018 at 11:10 pm #2761896

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us.

From what I understand, you're only using the default language IDs to exclude posts from the category, correct?

If so, have you tried using the secondary language IDs to filter the content of the terms? For example:

....
'terms' => array(103, 318, 317, secondary languages ID), // exclude exhibitions
'operator' => 'NOT IN'
.....

If you want this to be done dynamically, you can use the wpml_object_id hook: https://wpml.org/wpml-hook/wpml_object_id/

Following the above steps, is the problem solved?

Thank you.

September 28, 2018 at 11:22 am #2773519

Marc

Hi Bruno! Thanks for contacting.

Yes, I tried using secondary lang IDS. Actually
103 -> main language ID
318, 317 -> secondary languages IDs

I also tried with the wpml_object_id hook, with slugs instead of ids, etc..

Keep in mind that the problem disappears if the operator is 'IN' and not 'NOT IN'.

So far, I am unsetting the undesired results with a loop after the query.

hidden link

September 28, 2018 at 7:29 pm #2774739

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

Since Bruno currently has a few days off, I will replace him here in the forum. I hope this is OK for you.

I sent your code to our team to review, I'll send you feedback soon.

Regards,
Diego

October 1, 2018 at 11:47 am #2777893

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

I will need to escalate this ticket to our 2 tier support. For this, I will need a copy of the updated site and the page link with the issue. They will check the code and do some testing.

I tried to access the website using the credentials of the first post but they are incorrect. Could you check the password and update the live site code? I will generate a new duplicator package.

Regards,
Diego

The topic ‘[Closed] Can't get to work a tax_query with "NOT IN" operator for foreign languages’ is closed to new replies.