Custom Post Type with Elementor does not render including assets when being used via shortcode to include to another page

20 views Asked by At

I have created a custom post type. Each post content are built using elementor builder. I then use these as a shortcode to include it on another Page (also using elementor) but when I add the shortcode, it shows the cpt content but it does not render the exact look that I built from the cpt.

Can someone help me point out what Im missing from my shortcode so I can display the exact look I built from the cpt to another Page built also via elementor? It seems that the assets needed from the cpt are not rendered when used inside the page.

How do I render or pull the assets for my cpt post to work in another page.

Any guide/idea to fix this is appreciated.

Code below:

function _some_block_sc($atts,$content=null){
    $a = shortcode_atts( array(
        'id' => null,
    ), $atts );
    
    ob_start();
    ?>

    <?php 
        $mz_post = get_post($a['id']); //this id come from the cpt post
      
        if($mz_post->post_status == 'publish'){
       
            echo get_post_field('post_content', $a['id']);
        }
    
    ?>
    <?php
    
    return ob_get_clean();
}
add_shortcode('some_block','_some_block_sc');

Rendered output in the CPT using elementor

Output when cpt is added on another page using shortcode

I know that there are easier way to fix this as there is a function in Elementor to make a block save as template, but I need to use a shortcode instead of using the "save as template" function.

0

There are 0 answers