Q:

Echo a Wordpress function the_title() return value in table head

I have a Wordpress query:
$args = array('post_type' => 'food', 'posts_per_page' => 5, 'post__in'  => $ids, 'post_status' => 'any', 'orderby' => 'post__in');

    $query = new WP_Query( $args );

    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
                $query->the_post();

And I have a query result function the_title(); which save every title of the posts. I want to save those title values inside a table head. How can I do that?

A:

From the comments, this is the issue:
"<thead>" the_title() "</thead>";

You need to concatenate the escaped html tags as below. Notice the periods in between:
"<thead>" . the_title() . "</thead>";

or you close php to echo your html then open the php
$args = array('post_type' => 'food', 'posts_per_page' => 5, 'post__in'  => $ids, 'post_status' => 'any', 'orderby' => 'post__in');

    $query = new WP_Query( $args );

    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
                $query->the_post(); 

    /*You can escape the php by closing as below and enclose the title in php tags*/

?>
<thead><?php echo get_the_title(); ?></thead>

<?php endwhile; ?>

