Support

Account

Home Forums ACF PRO WPBakery / Visual composer post grid showing an ACF

Unread

WPBakery / Visual composer post grid showing an ACF

  • Hi all!
    I’m an experienced user of ACF but I’m facing a problem with showing a custom field in the WPBakery Post grid loop. Let me introduce you to what I want to do:

    I have a custom post called “Training” which has 2 custom fields: training_start_date and training_end_date. I want to show them on the Post Grid Element, for doing this I’ve eddited the Grid template and added a custom shortcode.

    This is the code that creates a VC shortcode:

    add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
    function my_module_add_grid_shortcodes( $shortcodes ) {
     $shortcodes['training_date'] = array(
     		'name' => __( 'Training Date', 'area-cs' ),
     		'base' => 'training_date',
     		'category' => __( 'Content', 'area-cs' ),
     		'description' => __( 'Show training date', 'area-cs' ),
     		'post_type' => Vc_Grid_Item_Editor::postType(),
      );
     return $shortcodes;
    }

    After that, I’ve created the ‘traning_date’ shortcode but the get_field function would not work, and I don’t know why.

    add_shortcode('training_date', 'training_date_render'); 
    function training_date_render(){
    	$postID = '{{ post_data:ID }}';
    	$o=$postID;
    	$o .= get_field( 'training_start_date', $postID);
    	$o .= ' – '.get_field('training_end_date', $postID);
    	return $o;
    }

    As you can see, I use the {{ post_data:ID }} element which is the way VC shares information with its shortcodes. And, indeed, the $o returns me a type string with the value of the ID. But the get_field function doesn’t work.

    I’ve tryied to call the ‘global $post;’ and other formulas but none worked.
    Could you please help me with this? As my intention is to make some operations with this dates so its not only by showing them.

    Thank you very much
    Regards

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.