:id: $singular = '/^singular:post_type:([^:]+):id:(\d+)$/i'; // Match singular:post_type::children:id: $singular_children = '/^singular:post_type:([^:]+):children:id:(\d+)$/i'; // Match singular:taxonomy::term:id: $singular_term = '/^singular:taxonomy:([^:]+):term:id:(\d+)$/i'; // Match archive:taxonomy::term:id: $archive_term = '/^archive:taxonomy:([^:]+):term:id:(\d+)$/i'; if ( preg_match( $singular, $a, $a_matches ) && preg_match( $singular, $b, $b_matches ) ) { $a_id = (int) $a_matches[2]; $a_id_translated = et_theme_builder_wpml_normalize_object_id( $a_id, 'post', $a_matches[1] ); $b_id = (int) $b_matches[2]; $b_id_translated = et_theme_builder_wpml_normalize_object_id( $b_id, 'post', $b_matches[1] ); } elseif ( preg_match( $singular_children, $a, $a_matches ) && preg_match( $singular_children, $b, $b_matches ) ) { $a_id = (int) $a_matches[2]; $a_id_translated = et_theme_builder_wpml_normalize_object_id( $a_id, 'post', $a_matches[1] ); $b_id = (int) $b_matches[2]; $b_id_translated = et_theme_builder_wpml_normalize_object_id( $b_id, 'post', $b_matches[1] ); } elseif ( preg_match( $singular_term, $a, $a_matches ) && preg_match( $singular_term, $b, $b_matches ) ) { $a_id = (int) $a_matches[2]; $a_id_translated = et_theme_builder_wpml_normalize_object_id( $a_id, 'taxonomy', $a_matches[1] ); $b_id = (int) $b_matches[2]; $b_id_translated = et_theme_builder_wpml_normalize_object_id( $b_id, 'taxonomy', $b_matches[1] ); } elseif ( preg_match( $archive_term, $a, $a_matches ) && preg_match( $archive_term, $b, $b_matches ) ) { $a_id = (int) $a_matches[2]; $a_id_translated = et_theme_builder_wpml_normalize_object_id( $a_id, 'taxonomy', $a_matches[1] ); $b_id = (int) $b_matches[2]; $b_id_translated = et_theme_builder_wpml_normalize_object_id( $b_id, 'taxonomy', $b_matches[1] ); } if ( $a_id && $a_id_translated && $a_id_translated === $a_id ) { // $a is an exact match for the current request and not a translated match so we prioritize it. return $a; } if ( $b_id && $b_id_translated && $b_id_translated === $b_id ) { // $b is an exact match for the current request and not a translated match so we prioritize it. return $b; } // Neither $a nor $b are exact matches so don't prioritize either. return $prioritized_setting; } add_filter( 'et_theme_builder_prioritized_template_setting', 'et_theme_builder_wpml_prioritize_translated_id', 10, 6 );