Search code examples
phphtmlwordpressshortcode

WP_Query shortcode output


i am trying to create shortcode but for some reason i have problem with the output,it should be inside < li > but it's outside

testPhoto 4Photo 3Photo then 3 li html tags

here is the code below:

    $the_query = new WP_Query( $args );

         if( $the_query->have_posts()): 

            while ( $the_query->have_posts() ) : $the_query->the_post();                       

            $output .= "<li>". the_title() . "</li>";                   

            endwhile; 

         endif; 

     wp_reset_query();               

    return $output; 

Solution

  • Calling the_title() without parameters directly outputs the value. According to the documentation to receive the value pass 3 parameters:

    the_title('', '', FALSE);
    

    The first two are strings added before and after the value.