Get Post ID in custom shortcode with Grid Builder Visual Composer

I’m trying to get some custom fields inside my custom grid builder. I have added some extra taxonomy and would like to add custom data to display. I’ve read this and when implementing it, I’m getting a problem when trying to get the id of the current post ID. I know the code is as follows:

add_shortcode( 'vc_post_id', 'vc_post_id_render' );
function vc_post_id_render() {
   return '<h2>{{ post_data:ID }}</h2>'; // usage of template variable post_data with argument "ID" 

The thing is that the {{ post_data:ID }} cannot be saved to a variable to later get the post and play with it as such:

$post_id = '{{ post_data:ID }}';
$post = get_post($post_id);

as it will fail. Could someone please tell me how to get the current post ID as a variable so I can show custom data on the grid? I need the taxonomy terms and in the only way to have it is through the get_post() function.

Thank you very much.


do you find a solution for doing that?

Thanks a lot

I’ve been looking for an answer to this issue for almost two days now. The double curly braces are familiar within javascript for instance as angular expressions. However post_type:ID is not an expression but an array. That combination I’v so far not found anywhere. In short: I’m still looking for an answer and quite frankly I’m close to giving up.

And just right after typing my previous comment I realize {{ post_data:ID }} is just a formatted string you parse back to the add_shortcode() function of wordpress. So, getting the ID from the post currently handled in the vc grid is not a matter of adding shortcodes. It requires some custom code that is called upon when the post is being handled in the grid.