Skip to content

Instantly share code, notes, and snippets.

@pavelthq
Last active September 26, 2017 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pavelthq/b1b7f517f20d3b528df8 to your computer and use it in GitHub Desktop.
Save pavelthq/b1b7f517f20d3b528df8 to your computer and use it in GitHub Desktop.
add_filter( 'vc_gitem_template_attribute_post_custom_meta', 'vc_gitem_template_attribute_post_custom_meta', 10, 2 );
function vc_gitem_template_attribute_post_custom_meta( $value, $data ) {
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract( array_merge( array(
'post' => null,
'data' => '',
), $data ) );
$atts_extended = array();
parse_str( $data, $atts_extended );
$atts = $atts_extended['atts'];
$output = print_r($atts, true); // will containt shortcode ATTS
$output .= print_r($post->ID, true); // will contain current POST_ID
$output .= print_r(get_post_meta($post->ID), true); // will contain current post meta..
return $output;
}
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_say_hello'] = array(
'name' => __( 'Say Hello', 'my-text-domain' ),
'base' => 'vc_say_hello',
'category' => __( 'Content', 'my-text-domain' ),
'description' => __( 'Just outputs Hello World', 'my-text-domain' ),
'post_type' => Vc_Grid_Item_Editor::postType(),
);
return $shortcodes;
}
add_shortcode( 'vc_say_hello', 'vc_say_hello_render' );
function vc_say_hello_render($atts){
/** @var $atts array - shortcode attributes */
$atts = vc_map_get_attributes( 'vc_say_hello', $atts );
return '{{ post_custom_meta:' . http_build_query( array(
'atts' => $atts,
) ) . '}}';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment