将循环的所有输出收集到一个变量中,将其包装在accordion shortcode中,然后通过do\\u shortcode传递:
$output = \'\';
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$output .= \'<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">\';
$output .= do_shortcode(\'[su_spoiler title="\'.get_the_title().\'" open="no" style="default" icon="plus" anchor="" class=""]\'.get_the_content().\'[/su_spoiler]\');
$output .= \'</div>\';
endwhile;
else :
$output = wpautop( \'Sorry, no posts were found\' );
endif;
echo do_shortcode( \'[su_accordion]\' . $output . \'[/su_accordion]\' );
我用几个封闭的短代码对此进行了测试,得到了预期的输出。