跳过导航

Open

Topic Tags: Compatibility

Overview of the issue

When using the Post Grid widget from the Unlimited Elements for Elementor plugin, the widget fails to fetch translated posts in the translated versions of the pages.

Workaround

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

  • Open your theme’s functions.php file.
  • Add the following code:
    // WPML Workaround for compsupp-7445
    add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7445_filter_ucaddon_post_grid');
     
    function wpml_compsupp7445_filter_ucaddon_post_grid($element) {
        if ( 'ucaddon_post_grid' !== $element->get_name() ) {
            return;
        }
     
        $settings = $element->get_settings();
     
        if ( isset( $settings['post_list_manual_select_post_ids'] ) && is_array( $settings['post_list_manual_select_post_ids'] ) ) {
            foreach ( $settings['post_list_manual_select_post_ids'] as $key => $id ) {      
     
                $post_type = get_post_type( $id );
     
                if ( ! $post_type ) {
                    continue;
                }
     
                $id = apply_filters( 'wpml_object_id', $id, $post_type, false );
     
                unset($settings['post_list_manual_select_post_ids'][$key]);
                $settings['post_list_manual_select_post_ids'][] = $id;
            }
     
            $element->set_settings( 'post_list_manual_select_post_ids', $settings['post_list_manual_select_post_ids'] );
        }
    	
        if (isset($settings['post_list_manual_post_ids_dynamic'])) {
            // Check if the IDs are in a string and convert them to an array
            if (is_string($settings['post_list_manual_post_ids_dynamic'])) {
                $settings['post_list_manual_post_ids_dynamic'] = explode(',', $settings['post_list_manual_post_ids_dynamic']);
            }
    
            // Proceed only if it's an array
            if (is_array($settings['post_list_manual_post_ids_dynamic'])) {
                foreach ($settings['post_list_manual_post_ids_dynamic'] as $key => $id) {
                    $post_type = get_post_type($id);
                    if (!$post_type) {
                        continue;
                    }
                    $translated_id = apply_filters('wpml_object_id', $id, $post_type, false);
                    $settings['post_list_manual_post_ids_dynamic'][$key] = $translated_id;
                }
                $element->set_settings('post_list_manual_post_ids_dynamic', $settings['post_list_manual_post_ids_dynamic']);
            }
        }	
    }
    

发表回复

保持话题相关并尊重他人。如果您需要与本帖无关的问题帮助,请使用我们的支持论坛开始聊天或提交工单。

您可以使用这些标签:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>