Shortcode with loop stacks output


I found some shortcode to display a custom post type, but it’s not display how I envisioned.

Originally the shortcode only added the title from my custom post type, but I modified it to also show the content…which works, but it groups the content together then displays the titles together.

I thought it would display them title1, content1 then title2, content2

What it’s doing is stacking them content1, content2 then title1, title2

Myfunctions.php looks like:

add_shortcode( 'faqs', 'faq' );
function faq() {
    $query = new WP_Query(array(
        'post_type' => 'faqs'
    while ($query->have_posts()) { 
        $output = $output.'<h2>'.get_the_title().'</h2>';
        $output = $output.the_content();
    return $output;

I feel like the code is pretty close, what do I need to change to get it to display how I expected?

The live example is at:

Any help is appreciated!


Josh Rodgers 1 month 0 Answers 4 views 0

Leave an answer