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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: America/Los_Angeles (GMT-07:00)

This topic contains 2 replies, has 2 voices.

Last updated by Bobby 1 year, 6 months ago.

Assisted by: Bobby.

Author Posts
September 30, 2022 at 12:48 pm #12156865

maartenD-4

Hey there
I want to repost a bug in the wpml latest version.

Ok so wordpress introduced a new filter for the function term_exists() since version 6.0.0

/**
* Filters default query arguments for checking if a term exists.
*
* @since 6.0.0
*
* @param array $defaults An array of arguments passed to get_terms().
* @param int|string $term The term to check. Accepts term ID, slug, or name.
* @param string $taxonomy The taxonomy name to use. An empty string indicates
* the search is against all taxonomies.
* @param int|null $parent ID of parent term under which to confine the exists search.
* Null indicates the search is unconfined.
*/
$defaults = apply_filters( 'term_exists_default_query_args', $defaults, $term, $taxonomy, $parent );

let's say i have the category Test (id = 31) and Test FR which is the translation of Test

Test FR has id 32

if i use term_exists(32) it will return array('id' => 31, 'term_taxonomy_id' => 31) which is the original language id , this breaks a lot of features when trying to save a post in the second language and adding the categories programmatically

September 30, 2022 at 1:30 pm #12157091

maartenD-4

Hey, i added this code in header.php.

get_categories(); <br/>
	<?php
	$args = array("hide_empty" => 0,
                    "type"      => "post",      
                    "orderby"   => "name",
                    "order"     => "ASC" );
      $types = get_categories($args);
		echo '<pre style="font-size: 12px;">'; var_dump($types); echo '</pre>';
	?>
	<br/>
term_exists(10);<br/>
	<?php
		var_dump(term_exists(10)); die;
	?>

Before the wordpress update if you used term_exists(10); (wich is the translated category from english in italian) you would get 10. now you get the category depending on the language you are. This affects all programatic and custom work because now you have to switch language in order to ge the correct id

October 4, 2022 at 1:38 am #12173465

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

Thank you for reproducing this behavior!

If possible, please review the following WPML Hook and let me know if that resolves this.

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

        echo apply_filters( 'wpml_object_id', 10, 'post' );

Notice the bottom where 10 shows now next to your var_dump

The topic ‘[Closed] I want to repost a bug in the wpml latest version.’ is closed to new replies.