1

I'm using Visual Composer, but I think it has more to do with WordPress than VC ;-) I did a shortcode (with the VC API) to get the content of a post. Here it is (in functions.php):

add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
    $shortcodes['vc_post_id'] = array(
 'name' => __( 'Post content', 'fluidtopics' ),
 'base' => 'vc_post_content',
 'category' => __( 'Content', 'fluidtopics' ),
 'description' => __( 'Show current post content', 'fluidtopics' ),
 'post_type' => Vc_Grid_Item_Editor::postType(),
);

return $shortcodes;
}

add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return '{{ post_data:post_content }}';
}

The content is really rendered. The layout provided by VC is achieved through shortcodes too... which are not parsed and displayed with the content. I wonder if it's possible to get these shortcodes parsed ?

This can be viewed here: https://www.fluidtopics.com/whats-new-2/ (third tab, you'll see [vc_row] etc.)

Thanks a lot for any help !

1

Here's the code given by the VC team. And it works.

// display content in grid
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_post_content'] = array(
    'name' => __( 'Post content', 'fluidtopics' ),
    'base' => 'vc_post_content',
    'category' => __( 'Content', 'fluidtopics' ),
    'description' => __( 'Show current post content', 'fluidtopics' ),
    'post_type' => Vc_Grid_Item_Editor::postType(),
);

return $shortcodes;
}

add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return '{{ do_shortcode_post_content }}';
}

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

function vc_gitem_template_attribute_do_shortcode_post_content( $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 );

WPBMap::addAllMappedShortcodes();

$output = do_shortcode( $post->post_content );
ob_start();
//  do_action( 'wp_enqueue_scripts' );
//  wp_print_styles();
//  wp_print_scripts();
//  wp_print_footer_scripts();
$output .= ob_get_clean();

return $output;
}
-1

you could try do_shortcode() - Code Reference

add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return do_shortcode('{{ post_data:post_content }}');
}

That should filter out the remaining shortcodes within the returned content.

2
  • did this not work? – Douglas.Sesar Dec 12 '15 at 3:29
  • Sorry for the delay Douglas. And thank you for your answer. I did try this before and it doesn't work. – Valentin Dec 14 '15 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.