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 34 replies, has 5 voices.

Last updated by Sumit 1 year, 8 months ago.

Assigned support staff: Sumit.

Author Posts
July 14, 2017 at 6:24 am #1319330

Paul

Hi

One of the striking theme users reported a issue and i was able to replicate this.

Since wp 4.8 the shortcode executed in the translated page is not calling the translated category anymore

I have one category for my custom post type "portfolio" called "gallery" the category is translated to "gallerij" for the dutch language. They both have 3 posts attached. Each for their own language.

I have this in my english page. [portfolio category="gallery"] calling the posts from the category gallery and it is showing 3 posts.

The page is duplicated into Dutch but the shortcode is the SAME. So the dutch page also has [portfolio category="gallery"] and NOT [portfolio category="gallerij"]. So the dutch page is calling the English category.

Now in wp 4.7.x this works perfectly and the dutch page shows the dutch portfolio items.

But the moment wp 4.8 is installed the dutch page is empty and i need to set the Dutch page with the shortcode to translated independently and change the shortcode manually to [portfolio category="gallerij"] so that it is calling the dutch category called "gallerij"

What changed in the wpml code? The striking Team did not change the theme code.

I tested this 3 x times now in a clean wp install on my local host and i get similar results all the time.

If i revert to wp 4.7 there is no issue. If i activate wp 4.8 the issue occurs and the translated page is empty not showing any portfolio items.

You can see it happen here (its one of the theme users and the one reporting the issue)

This is wp 4.8 hidden link

This is wp 4.7.4 hidden link

Note : i tested this in my local host and was able to reproduce the same issue over and over again by reverting back and forth to wp 4.7.4 and 4.8.

Note : the categories are synchronized !! There is no issue in using the settings wrong or whatever.

July 14, 2017 at 7:05 am #1319355

Paul

similar thread found here https://wpml.org/forums/topic/taxonomy-translation-id-mismatch-in-wordpress-4-8/

This code fails in wp 4.8

	if($cat != ''){
			$query['tax_query'] = array(
				array(
					'taxonomy' => 'portfolio_category',
					'field' => 'slug',
					'terms' => explode(',', $cat)
				)
			);
		}
July 14, 2017 at 7:37 am #1319390

Paul

in wp 4.7.x this

$term_slug='gallery';
$term_data = get_term_by( 'slug', $term_slug, 'portfolio_category' );
$term_id = (int) $term_data->term_id; 
echo 'term-id :'.$term_id;

returns the id of the translated category in the translated page.

in wp 4.8 and above it returns 0 for that category in the translated page but the correct id in the page with primary original language.

So there are two faillures here.

The get_term_by fails but also the query fails... see previous reply. They both return nothing when wp 4.8 is used. $cat a list of category slugnames in the original default language

	$query['tax_query'] = array(
		array(
			'taxonomy' => 'portfolio_category',
			'field' => 'slug',
			'terms' => explode(',', $cat)
		)
	);
	
	$r = new WP_Query($query);

Pls provide a fix.

July 14, 2017 at 8:44 am #1319449

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

Hello Paul ,

Welcome to WPML support forum.

Thank you very much for bringing us this detailed report. Our developers our already aware of this situation, and as you can see both comes from the fact that get_term_by() function is returning false for slug in secondary languages.

If you check the query for $term in tax_query, you will see that it also uses the get_terms() as well:

switch ( $field ) {
        case 'slug' :
            $args['slug'] = $value;
            break;
        case 'name' :
            $args['name'] = $value;
            break;
        case 'term_taxonomy_id' :
            $args['term_taxonomy_id'] = $value;
            unset( $args[ 'taxonomy' ] );
            break;
        default :
            return false;
    }

    $terms = get_terms( $args );

As temporary workaround, could you please use the ID instead of the slug for both cases?

Best regards,
Andrés

July 14, 2017 at 12:44 pm #1319681

Paul

Hi Andrés

I already tried to work around. But we have over 15.000 striking websites with already generated shortcodes that dont work. But even adjusting the shortcode execution and grab the id of the parent category in the translated page from the correct english category name does not work as it returns me a 0 on trying to get the id. Unless i am missing something i could not resolve the issue for the moment and have to advice people to use wp 4.7.x

But it would also mean that we have to release e intermediate theme update just to fix this issue.

Please keep me posted. Thanks for any suggestion.

Best regards,
Paul

July 14, 2017 at 2:31 pm #1319786

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

I'm sorry to hear that, Paul. Have you tried something like this?

<?php $term = get_term_by( 'id','id_number, 'category' );?>

On the other hand, if I understand correctly you are a theme author, am I right? Is your theme part of our Go Global Program? It it is not, I invite to join it, in that way you will have a direct channel with our devs:
https://wpml.org/documentation/theme-compatibility/go-global-program/

Regards,
Andrés

July 18, 2017 at 1:25 pm #1321936

Paul

Hi Andrés

We are already part of that..... 🙂 https://wpml.org/theme/striking-multiflex/

Any news or progress on this issue? ETA?

Looking forward to your reply.

July 18, 2017 at 2:32 pm #1322000

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

Hello Paul,

That's great, I have already informed our compatibility team about your situation. In the meantime, we just have published the following errata about this issue:

Errata:
https://wpml.org/errata/functions-tax_query-and-get_term_by-return-false-for-slug-and-name-parameters/

I'll keep you informed,
Andrés

July 18, 2017 at 2:49 pm #1322011

Paul

Hi

How does this solution work when you have a shortcode in a PAGE to build a portfolio list based on a selected category?

[portfolio cat="gallery"]

The moment i am in the translated page i get NULL

Is this caused by WP?

Best regards,
Paul

July 18, 2017 at 2:56 pm #1322018

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

I'm not familiar with the code of you theme but I guess you are passing the "gallery" parameter as slug or name. I think it would be better to contact our compatibility team as at this point I couldn't tell you how to bypass with situation, or wait for the evolution of this ticket.

I'll keep you informed.

Regards,
Andrés

July 18, 2017 at 2:59 pm #1322024

Paul

Yes i am passing it as a slug. It could be a array when multiple categories are selected. That shortcode can be in a page, a post, a text widget, or a portfolio item itself.

It is a real problem.... thank you for any suggestion.

July 20, 2017 at 8:42 am #1323401

Paul

FYI : To add to this we also use ajax filtering where we use the (translated) term name to trigger the filter. So it is really necessary that we have the correct term name and or are able to retrieve that. Anyway i took the time to post this on wordpress as the issue also occurs in other multilanguage plugins. https://core.trac.wordpress.org/ticket/41373

July 20, 2017 at 9:29 am #1323449

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

Thank you very much, Paul.

I understand the importance of your problem, I have transmitted your core ticket immediately to our developpers.

I'll keep you informed.

Regards,
Andrés

July 27, 2017 at 4:02 pm #1329059

Pau

Hi,
I have just been affected by this bug after updating to WP 4.8. And I don't want to hijack this thread, but since I have not seen it said on any of the threads related to this bug, I want to add that strangely when logged in to the admin both tax_query and get_term_by work. Checked and the parameters to get_term_by are exactly the same.
EDIT: forgot to mention that this happens on an AJAX request, so this may change things
Hope this helps
Pau

July 28, 2017 at 7:01 am #1329388

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

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

Hello Pau,

I'm not able to reproduce your situation and it may not be related. Please, check that you have checked the following setting:
- WPML > Langauges.
- Language filtering for AJAX operations
x Store a language cookie to support language filtering for AJAX

If this does not help, please create a new ticket. 🙂

Regards,
Andrés