im using shortcode in a php template file for wordpress, because the shortcode opens and closes I need to get the entire content within it as one variable. In this case the content is a wordpress loop.
So far what I have only displays the final post of the loop. I understand why, as that is what the final value of the variable is. Im wondering could someone help me get the entire contents (ie all three posts) into a variable, as oppose to just the final post.
Thanks
<?php
$news_title .= '';
$news_single_post .= '';
if ( have_posts() ) :
$the_query = new WP_Query( array ( 'posts_per_page' => 3, 'cat' => 1 ) ); /* */
while ($the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$news_title = get_the_title();
$news_excerpt = get_the_excerpt();
$news_single_post = '<div class="home-content-news-title">'.$news_title.'</div><div class="home-content-news-excerpt">'.$news_excerpt.'</div>';
endwhile;
wp_reset_postdata();
endif;
$news_tab_title_string = 'News';
$news_tab_title_shortcode = do_shortcode('[wptabtitle]'.$news_tab_title_string.'[/wptabtitle]');
$news_tab_content_shortcode = do_shortcode('[wptabcontent]'.$news_single_post.'[/wptabcontent]');
$news_tab = $news_tab_title_shortcode.$news_tab_content_shortcode;
echo do_shortcode('[wptabs]'.$news_tab.'[/wptabs]');
?>