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 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 -
- 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 -

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

This topic contains 33 replies, has 2 voices.

Last updated by davidR-15 1 year, 1 month ago.

Assisted by: Nigel.

Author Posts
March 20, 2024 at 12:01 pm #15431068

davidR-15

Yes, it's those plug-ins that define the CPTs and taxonomies.

The fatal error may stem from the fact that the plug-ins are trying to connect to an mssql server.
You can avoid that by setting an environment variable named APP_ENV to the value 'development'. They will then instead try to a different IP (on a local or docker network).

If you can privately communicate details of the fatal error, I could say more about it and perhaps supply a version of both plug-ins that won't try to connect and won't throw. That in the sense of allowing you to proceed on a staging env. rather than the production.

If push comes to shove, let me know and I can ensure we have backups of the prod environment just before your intervention.

March 20, 2024 at 12:14 pm #15431220

davidR-15

OK, I have a version available that will not check for the presence of that PHP extension.
Could you allow me to reply via private message so I can share the URL ?

March 20, 2024 at 12:26 pm #15431329

Nigel
WPML Supporter since 02/2016

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

The private replies have templates for providing log-in credentials etc.

You can just paste a link to dropbox, wetransfer or similar in your reply.

Such external links are automatically hidden from other users, only you and support can see them.

March 20, 2024 at 12:28 pm #15431344

davidR-15

OK, I didn't realize they'd be hidden by default.

hidden link

You'll probably only need the agenda one.

March 20, 2024 at 3:19 pm #15432576

Nigel
WPML Supporter since 02/2016

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

That works, I have the local copy of the site working.

Can I get some history about how the content to the site was added, and how it was translated?

I'm not sure what I should expect to see.

For example, looking at the eag-adultes-fr term of the mnhn-age-group taxonomy, assigned to the mnhn-event post type.

I've been querying the db directly to get a sense of the underlying data.

This simple query (you can perhaps check it yourself) is to see which posts have the eag-adultes-fr term assigned to them, and what is their language.

SELECT wp_posts.ID, wp_posts.post_title, wp_icl_translations.language_code, wp_icl_translations.source_language_code, wp_term_relationships.object_id, wp_term_relationships.term_taxonomy_id
FROM 
    wp_posts
JOIN 
    wp_term_relationships
ON 
    wp_posts.ID = wp_term_relationships.object_id
JOIN 
    wp_icl_translations
ON 
    wp_posts.ID = wp_icl_translations.element_id
AND
    wp_icl_translations.element_type = CONCAT('post_', wp_posts.post_type)
WHERE
	wp_posts.post_type = 'mnhn-event'
AND
	wp_posts.post_status = 'publish'
AND
	wp_term_relationships.term_taxonomy_id IN(163)

You can see a sample of the results in the screenshot.

163 is the ID of the French age-group term for adults, but all of the mnhn-event posts which have that term assigned are either DE or LU, translated from FR, and none of them are FR posts.

That's clearly wrong, and before going much further I want to understand the history of the site to know how this may have come about.

Screenshot 2024-03-20 at 15.12.09.png
March 21, 2024 at 9:54 am #15435308

davidR-15

Nigel, many thanks for you efforts so far. I am on the road today, I will look into this as soon as I can.

March 22, 2024 at 8:57 am #15439396

Nigel
WPML Supporter since 02/2016

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

OK, just to note I'll be off today, if you get back to me it will be Monday before I can respond.

March 25, 2024 at 7:49 am #15444955

davidR-15

I hope you were able to enjoy your day off. Not a problem since I still didn't get to it. We have a very high workload at the moment.

March 25, 2024 at 2:01 pm #15447197

Nigel
WPML Supporter since 02/2016

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

OK, well let me set this as awaiting your feedback, and you can reply when you have time.

March 29, 2024 at 5:16 pm #15465174

davidR-15

Hi Nigel,

I finally made the time to take a closer look.
I found out what is adding the `0 = 1` clause.

So, at the base, we're defining a tax_query, e.g.

```
[
'taxonomy' => 'sometaxonomy',
'field' => 'slug',
'terms' => [ 'term1', 'term2' ],
'operator' => 'IN'
]
```

WordPress' WP_Tax_Query class will attempt to convert this into an SQL clause using term ids.
However, if it fails, it will return `$no_result`, which is:

```
/**
* Standard response when the query should not return any rows.
*
* @since 3.2.0
* @var string
*/
private static $no_results = array(
'join' => array( '' ),
'where' => array( '0 = 1' ),
);
```

It does this e.g. here:

```
public function get_sql_for_clause(&$clause, $parent_query) {
[…]
$this->clean_query( $clause );
[…]
if ( 'IN' === $operator ) {

if ( empty( $terms ) ) {
return self::$no_results;
}

```

In this case, `WP_Tax_Query::clean_query` removes all terms from the clause when it runs the `WP_Term_Query`. – So yeah, this is quite a hunt…

Eventually, it boils down to the `get_term_args` filter. WPML hooks into it and replaces the correct term_ids with the term IDs in another language.

This creates a WHERE that cannot work because the term_ids are for German and the language_code it requests is for French:

```
[where] => tt.taxonomy IN ('tax-age-group') AND t.term_id IN ( 154,157,160 ) AND ( ( icl_t.element_type IN ('tax_tax-age-group') AND ( icl_t.language_code = 'fr' OR 0 ) )
```

March 29, 2024 at 5:32 pm #15465221

davidR-15

I have spent hours on this already, and it all boils down to this line of code returning the wrong IDs for the terms:

```
function adjust_taxonomies_terms_ids()
[…]
$translated_id = $this->term_translation->term_id_in( $term->term_id, $this->current_language );
[…]
}
```

I feel like at this point, I'd have to deep dive into WPML to figure out why and not only is that not my job, it's also almost impossible to follow all the different functions.

Something is seriously broken with this installation and at this point I really no longer know what to do.

April 2, 2024 at 10:13 am #15472042

Nigel
WPML Supporter since 02/2016

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

I think what you are seeing with the queries, and why they are failing in an unintended way, is that the data itself is problematic, as I outlined in https://wpml.org/forums/topic/trying-to-get-property-post_type-of-non-object-in-class-wpml-term-actions/page/2/#post-15432576

Sorry, it wasn't my intention that you spend a long time digging into the WPML code, I was simply looking for some history of your site to know how and why it got that way.

Language-specific terms are assigned to posts of other languages.

I'm looking at how to fix that, and working on it now.

I'll get back to you in a little while.

April 5, 2024 at 4:40 pm #15489128

Nigel
WPML Supporter since 02/2016

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

My apologies, I thought I had written back to you, but I realise I hadn't.

I'm just finishing up, but let me just share that the intention is essentially to run through all the posts in French which wrongly have DE or LU terms assigned to them, to look up what the FR version of the term is, assign that, and unassign the wrong terms.

Then run the troubleshooting step which mirrors the assignments of terms in the default language to the secondary languages.

I assume that is the intention on your site, that the posts in the different languages should all have the same (translated) terms assigned to them.

April 5, 2024 at 4:47 pm #15489151

davidR-15

> I assume that is the intention on your site, that the posts in the different languages should all have the same (translated) terms assigned to them.

Yes, that's correct.

> all the posts in French which wrongly have DE or LU terms assigned to them,

I've never observed that, at least not on the UI. Are you saying there are e.g. French Posts that have a German term_id pointing to them instead of the French term_id ?

Since you asked about the history of the site:

It's been running for a very, very long time with little to no changes to how these contents are created. And this problems only started to occur very recently.

April 8, 2024 at 6:51 am #15492598

Nigel
WPML Supporter since 02/2016

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

>Are you saying there are e.g. French Posts that have a German term_id pointing to them instead of the French term_id ?

Yes, that's what I was pointing out back in https://wpml.org/forums/topic/trying-to-get-property-post_type-of-non-object-in-class-wpml-term-actions/page/2/#post-15432576

Sorry if that wasn't clear.

So my intention is to fix the French posts so that they have French terms assigned (by inferring the correct French term from the DE or LU term which is actually assigned), and then run the troubleshooting batch process to then update the DE and LU posts to have the corresponding terms in their own language.

OK, I'll go ahead with that on my copy of your site, and when I confirm it works, I'll share the code with you.

The topic ‘[Closed] Trying to get property 'post_type' of non-object in class-wpml-term-actions’ is closed to new replies.