I’ve created a shortcode which outputs a slider generated by another custom post type. I would like to display this within the a field generated by the flexible content creator.
I’ve inserted the shortcode within the field in admin and the slider appears on the the page but outside of the column div I’ve set within the loop.
Is there a way of passing the shortcode through so that it displays in the correct div?
Code loop below.
<?php if(get_sub_field("content_1")): ?>
<div class="col-md-<?php echo $column_span; ?>">
<?php the_sub_field('content_1'); // display column content ?>
<?php $arr[] = get_sub_field("content_1"); // add content to image map array ?>
</div>
<?php endif; ?>
I ran into this issue and this article helped http://kovshenin.com/2013/get_template_part-within-shortcodes/.
1. Put the loop in a php file.
2. Then set up your shortcode like this:
function myshortcode( $attr ) {
ob_start();
get_template_part(‘php’,’file’);
return ob_get_clean();
}
add_shortcode( ‘shortcode’, ‘myshortcode’ );