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.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by peterL-60 10 months, 3 weeks ago.

Assigned support staff: Marcel.

Author Posts
July 6, 2021 at 7:03 pm #9142291

peterL-60

We have a global blacklist of post IDs that should be excluded from queries. This list includes IDs from any/all languages. We pass this blacklist into WP_Query using the 'post__not_in' query arg.

In this case a translated version of a post (JP) is on this blacklist. However the KR version of the post is not on the blacklist. When the query is performed on the KR site, the JP post ID gets changed to the KR post ID, causing the KR version of the post to be excluded from the query even though it does not appear on our blacklist.

Looking through the code from the WPML plugin, I see that on line #432 of /sitepress-multilingual-cms/classes/query-filtering/class-wpml-query-parser.php, it calls the adjust_q_var_pids function which is responsible for this issue. I assume that this must be desired functionality in other areas, but is not desired in this case.

I do not see any hooks/filters in the WPML code to allow me to skip this functionality. How can I prevent these post__not_in post IDs from being adjusted?

July 7, 2021 at 9:31 am #9145527

Marcel
Supporter

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

Hi,

are we talking about a custom query?

It's quite normal to adjust the id on the fly. Please try if you can solve it using “Auto-adjust IDs” option – try turning it off or on depending on its current state: https://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/#1-automatically-adjust-ids

Another thing to consider is that if you do a custom query, they might want to use suppress_filters => true.

Best Regards
Marcel

July 7, 2021 at 10:09 pm #9151893

peterL-60

Yes this is a custom query. I will try out the auto-adjust IDs option you suggested and see if that works for us. I've already tried supress_filters => true which didn't seem to have an effect.

July 8, 2021 at 7:18 am #9153721

Marcel
Supporter

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

Sure, let me know how it goes.

Best Regards
Marcel

July 8, 2021 at 8:08 pm #9160145

peterL-60

Unfortunately I believe disabling the auto-adjust IDs option you mentioned would fix this issue, but we have other areas of the site that rely on it which would then break.

I ended up having to redesign how our post ID blacklists work so that we now maintain a separate blacklist for each language of the site to avoid this quirk.