Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nuriye/8dfa912375034778bea128eed6ac8bc4 to your computer and use it in GitHub Desktop.
Save nuriye/8dfa912375034778bea128eed6ac8bc4 to your computer and use it in GitHub Desktop.
add_shortcode('wps_event_link', 'wps_event_link');
function wps_event_link() {
$post_id = '{{ post_data:ID }}';
}
@indextwo
Copy link

Just a heads-up for anyone else who stumbles across this - all this will do is assign $post_id as a rendered string value - essentially acting like a template tag. In PHP it has no value beyond the string {{ post_data:ID }}. So if you did:

echo $post_id;   // Outputs '123', because it's rendered as that value after the fact by a WPB filter
echo get_post_meta($post_id, 'juice_flavour', true);   // Outputs nothing, because {{ post_data:ID }} isn't a valid ID
///
//	Okay, so a regular old shortcode won't cut it, so we're creating a CUSTOM VARIABLE specifically for the WPB Grid, and then using the shortcode to output THAT
///

So instead you want to create your own custom template variable that gets the post ID and puts together all the info, and then you can use a very simple shortcode to simply output that template variable:

function vc_gitem_template_attribute_book_release($value, $data) {

	extract(array_merge(array(
		'post' => null,
		'data' => '',
	), $data));

	//	$post is now available as a regular WP post object

	$bookID = $post->ID;

	$release_date = get_post_meta($bookID, 'book_release_date', true);

	ob_start();
	
	echo '<h2>' . $release_date . '</h2>';

	return ob_get_clean();
}

add_filter('vc_gitem_template_attribute_book_release', 'vc_gitem_template_attribute_book_release', 10, 2);

///
//	And now the very basic shortcode
///

function book_release_shortcode_wpb_render($atts, $content, $tag) {
    return '{{book_release}}';
}

add_shortcode('book-release', 'book_release_shortcode_wpb_render', 10, 3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment