Visual Composer Grid with do_action shortcode is not working

Viewed 9857

I have visual composer which is packed with total theme. When I put the following grid short code in my page in the editor it works correctly.

[vc_basic_grid post_type="post_type" max_items="10" item="masonryGrid_SlideFromLeft" grid_id="vc_gid:1458178666639-80ebf3775500c87d35de078c3422fe96-10" taxonomies="555"]

However, when I call the exact same code using do_action it gives the following javascript error. I checked the html output and it is the same using do_action like putting the short code in editor.

Error: Syntax error, unrecognized expression: {'status':'Nothing found'} s

Any help is greatly appreciated.

5 Answers

I've solved.
I had the same problems, with the Visual Composer Editor offered by WpBakery https://wpbakery.com/
and after understanding the connection between the IDs of the block, and the ID of the Post, I put more attention to the settings of the Block.

There is infact one field called "Element ID", and here we have to put our ID of the Post we are editing.

In my case the Block was a block containing some Posts.

enter image description here

After saving, and viewing the page without the Editor, I was finally able to see the block, and not the message

{"status":"Nothing found"}

I found a solution to this problem. I modified the woocommerce category template and linked to the woocommerce_archive_description hook to add additional descriptions from some pages, for this I got their id, and then display the content.

echo do_shortcode($post->post_content);

The gallery(media grid) didn't work because there was a mismatch between the page id and the shortcode id. Therefore, the logical solution was to redefine the global variable $post to the $post of the page from which I get the content.

global $post;
$post = get_post( $id );

And it turns out that the post id matches.

After that, don't forget to return the normal $post value;

wp_reset_postdata();

By the way - use this option to load custom styles for wpbakery elements.

echo '<style type="text/css" data-type="vc_shortcodes-custom-css">' . get_post_meta( $id, '_wpb_shortcodes_custom_css', true ) . '</style>';

The whole code

function extra_product_category_desc(){
    if( is_product_category() ){
        $id = get_term_meta (get_queried_object()->term_id, 'pageId', true);
        if($id !== ''){
            global $post;
            $post = get_post( $id );
            echo do_shortcode($post->post_content);
            echo '<style type="text/css" data-type="vc_shortcodes-custom-css">' . get_post_meta( $id, '_wpb_shortcodes_custom_css', true ) . '</style>';
            wp_reset_postdata();
        }
    }
}
add_action( 'woocommerce_archive_description', 'extra_product_category_desc', 11 );
Related