I am using a plugin that has shortcodes. It is called according shortcodes
[accordion]
[accordion-item title="Title of accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item title="Second accordion item"]Drop-down content goes here.[/accordion-item]
[/accordion]
I wanted put it in a wp_query, but i can't seem to figure out how to nest the shortcode. Can someone please help?
This is what I already tried:
<?php echo do_shortcode ('[accordion]'); ?>
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $quicksand_categories
);
$query = new WP_Query( $args );
foreach ($query->posts as $item) {
$categories = wp_get_post_categories($item->ID);
?>
<?php echo do_shortcode ('[accordion-item title="'.get_the_title($item->ID).'"]'.the_content().'[/accordion-item]'); ?>
<?php } ?>
<?php echo do_shortcode ('[/accordion]'); ?>
I am using a plugin that has shortcodes. It is called according shortcodes
[accordion]
[accordion-item title="Title of accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item title="Second accordion item"]Drop-down content goes here.[/accordion-item]
[/accordion]
I wanted put it in a wp_query, but i can't seem to figure out how to nest the shortcode. Can someone please help?
This is what I already tried:
<?php echo do_shortcode ('[accordion]'); ?>
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $quicksand_categories
);
$query = new WP_Query( $args );
foreach ($query->posts as $item) {
$categories = wp_get_post_categories($item->ID);
?>
<?php echo do_shortcode ('[accordion-item title="'.get_the_title($item->ID).'"]'.the_content().'[/accordion-item]'); ?>
<?php } ?>
<?php echo do_shortcode ('[/accordion]'); ?>
I think it needs to be like this:
<?php $output = '[accordion]'; ?>
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $quicksand_categories
);
$query = new WP_Query( $args );
foreach ($query->posts as $item) {
$categories = wp_get_post_categories($item->ID);
?>
<?php $output.='[accordion-item title="'.get_the_title($item->ID).'"]'.the_content().'[/accordion-item]'; ?>
<?php } ?>
<?php $output .= '[/accordion]'; ?>
<?php echo do_shortcode($output); ?>
An alternative approach for using opening/closing shortcodes in a template, that doesn't require a lot of string concatenation:
<?php
// Buffer the output so that we can use [shortcodes][/shortcodes]
ob_start();
?>
<h1>A stylish template</h1>
[my_whizzy_shortcode param="awesome"]
<p><?= the_content() ?></p>
<div>More template html, php tags, etc</div>
[/my_whizzy_shortcode]
<?php
// Now write out the template, including the parsed shortcodes
echo do_shortcode(ob_get_clean());
?>