Hi @charlie!
I am in the middle of translating a website with WPML. I run into an issue with conditions on layouts.
I managed to get Claude Code fixing it, so I asked it to write the post for you. Here it is:
When using element conditions like archive:post-type-with-term|product|product_cat with a term ID value, the condition fails on translated pages because WPML assigns different term IDs per language.
Example:
- Croatian term “Bezglutenski kruh” = ID 17
- English translation “Gluten-free bread” = ID 42
- Condition set to
product_cat = 17→ works on Croatian, hidden on English
Root cause: ConditionRules::archive_post_type_with_term() passes the stored term ID directly to is_tax() without translation.
Fix: Hook into cs_condition_args and translate term IDs using WPML’s wpml_object_id filter:
add_filter( 'cs_condition_args', function( $args ) {
if ( count( $args ) !== 3 || ! is_numeric( $args[2] ) ) {
return $args;
}
if ( ! taxonomy_exists( $args[1] ) || ! has_filter( 'wpml_object_id' ) ) {
return $args;
}
$translated_id = apply_filters( 'wpml_object_id', (int) $args[2], $args[1], true );
if ( $translated_id ) {
$args[2] = $translated_id;
}
return $args;
}, 10, 1 );
Suggested core fix: Add WPML translation in RuleMatching::evaluate() before calling condition handlers, or within ConditionRules::archive_post_type_with_term() itself.
Thanks!