Sauter la navigation

Waiting for author

Topic Tags: Compatibility

Overview of the issue

In Bricks Theme, when a template condition is set to display only for specific terms (e.g., a particular category), the condition does not apply correctly in the translated templates.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

Part I

  • Go to WPML > Settings > Custom fields.
  • Look for line the _bricks_template_settings field.
  • Set it as Copy

Part II

  • Open your theme’s functions.php file.
  • Add the following code:
    /**
     * WPML Workaround for compsupp-7667
     */
    add_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10, 4);
    function wpml_compsupp7667_bricks_translate_template_conditions($value, $post_id, $key, $single) {
        if ($key !== '_bricks_template_settings') {
            return $value;
        }
    
        // Remove filter temporarily to avoid infinite loop
        remove_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10);
        
        // Get all meta values
        $raw_values = get_post_meta($post_id, $key, false);
        
        // Add filter back
        add_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10, 4);
    
        // If we have no values, return the original
        if (empty($raw_values)) {
            return $value;
        }
    
        // Process the array structure
        foreach ($raw_values as &$settings) {
            if (is_array($settings) && isset($settings['templateConditions'])) {
                foreach ($settings['templateConditions'] as &$condition) {
                    if (!empty($condition['archiveTerms']) && is_array($condition['archiveTerms'])) {
                        foreach ($condition['archiveTerms'] as &$termString) {
                            if (strpos($termString, '::') !== false) {
                                list($taxonomy, $termId) = explode('::', $termString);
                                $translatedId = apply_filters('wpml_object_id', intval($termId), $taxonomy, true);
                                if ($translatedId) {
                                    $termString = $taxonomy . '::' . $translatedId;
                                }
                            }
                        }
                    }
                }
            }
        }
    
        return $raw_values;
    }
    

2 Réponses à “Bricks Theme: Template Conditions Not Applied Correctly in Translated Templates”

  1. I’m experiencing this problem with one of my templates for a custom post type post. I’m using the latest versions of all software and implemented the workaround suggested here but the template still isn’t applied for my posts in other language versions.
    I also tried translating the template using the WordPress editor, resaving settings and translations after the change.
    Is there something else I can try? Thanks.

Laisser une réponse

Veuillez rester dans le sujet et respecter les autres. Si vous avez besoin d'aide pour des questions qui ne sont pas liées à ce message, utilisez notre Forum d'assistance pour entamer une discussion ou soumettre un ticket.

Vous pouvez utiliser ces balises :
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>