Title: Return multiple Posts as single table
Last modified: April 21, 2017

---

# Return multiple Posts as single table

 *  [samchief](https://wordpress.org/support/users/samchief/)
 * (@samchief)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/return-multiple-posts-as-single-table/)
 *     ```
       query_posts( array(
       'post_type' => 'ts_result',
       'meta_query' => array(
       array(
       'key' => '_ts_student_class',
       'value' => $exam_reg,
       'compare' => '='
       ),
       array(
       'key' => '_ts_school_term',
       'value' => $exam_term,
       ),
       array(
       'key' => '_ts_school_year',
       'value' => $exam_year,
       )
       ),
       'posts_per_page' => 100
       )
       );
       ?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <table style="border:1px solid black" cellpadding="1.5" cellspacing="5">
       <style type="text/css" media="print">
   
       table{
       border-collapse:collapse;
       }
       </style>
       <tbody>
   
       <tr>
       <th><strong>NAME\SUBJECT</strong></th>
       <th><strong>English Studies</strong></th>
       <th align='center' ><strong>Mathematics</strong></th>
       <th align='center'><strong>CCA</strong></th>
       <th align='center'><strong>Yoruba Language</strong></th>
       <th align='center'><strong>French</strong></th>
       <th align='center'><strong>Business Education</strong></th>
       </tr>
   
       <?php 
       $subject_english_studies_exam_total= get_post_meta( get_the_ID(),'_ts_subject_english_studies_exam_total',true );
       $subject_maths_exam_total= get_post_meta( get_the_ID(),'_ts_subject_maths_exam_total',true );
       $subject_creative_arts_exam_total= get_post_meta( get_the_ID(),'_ts_subject_creative_arts_exam_total',true );
       $subject_yoruba_lang_exam_total= get_post_meta( get_the_ID(),'_ts_subject_yoruba_lang_exam_total',true );
       $subject_french_exam_total= get_post_meta( get_the_ID(),'_ts_subject_french_exam_total',true );
       $subject_business_edu_exam_total= get_post_meta( get_the_ID(),'_ts_subject_business_edu_exam_total',true );
       ?>
   
       <tr>
       <td><?php the_title(); ?></td>
       <td><?php echo $subject_english_studies_exam_total ;?></td>
       <td><?php echo $subject_maths_exam_total ;?></td>
       <td><?php echo $subject_creative_arts_exam_total ;?></td>
       <td><?php echo $subject_yoruba_lang_exam_total ;?></td>
       <td><?php echo $subject_french_exam_total ;?></td>
       <td><?php echo $subject_business_edu_exam_total ;?></td>
       </tr>
       </tbody>
       </table>
       ```
   
 * The code above returns each post as an individual table of its own.
    Screenshot:(
   [https://drive.google.com/open?id=0BzoS3oOkVoTtckFjbFpiQnB6aE0](https://drive.google.com/open?id=0BzoS3oOkVoTtckFjbFpiQnB6aE0))
   I want them returned as a single table, with one table head and with each post
   as a row. How do I go about that, thanks.

Viewing 1 replies (of 1 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/return-multiple-posts-as-single-table/#post-9051739)
 * You have to move the `if()` and `while()` inside the tables HTML code. As an 
   example…
 *     ```
       <table style="border:1px solid black" cellpadding="1.5" cellspacing="5">
           <tbody>
               <tr>
                   <th><strong>NAME\SUBJECT</strong></th>
                   <th><strong>English Studies</strong></th>
                   <th align='center' ><strong>Mathematics</strong></th>
                   <th align='center'><strong>CCA</strong></th>
                   <th align='center'><strong>Yoruba Language</strong></th>
                   <th align='center'><strong>French</strong></th>
                   <th align='center'><strong>Business Education</strong></th>
               </tr>
   
               <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
                   <?php 
                       $subject_english_studies_exam_total= get_post_meta( get_the_ID(),'_ts_subject_english_studies_exam_total',true );
                       $subject_maths_exam_total= get_post_meta( get_the_ID(),'_ts_subject_maths_exam_total',true );
                       $subject_creative_arts_exam_total= get_post_meta( get_the_ID(),'_ts_subject_creative_arts_exam_total',true );
                       $subject_yoruba_lang_exam_total= get_post_meta( get_the_ID(),'_ts_subject_yoruba_lang_exam_total',true );
                       $subject_french_exam_total= get_post_meta( get_the_ID(),'_ts_subject_french_exam_total',true );
                       $subject_business_edu_exam_total= get_post_meta( get_the_ID(),'_ts_subject_business_edu_exam_total',true );
                   ?>
                   <tr>
                       <td><?php the_title(); ?></td>
                       <td><?php echo $subject_english_studies_exam_total ;?></td>
                       <td><?php echo $subject_maths_exam_total ;?></td>
                       <td><?php echo $subject_creative_arts_exam_total ;?></td>
                       <td><?php echo $subject_yoruba_lang_exam_total ;?></td>
                       <td><?php echo $subject_french_exam_total ;?></td>
                       <td><?php echo $subject_business_edu_exam_total ;?></td>
                   </tr>
   
               <?php endwhile; endif; ?>
   
           </tbody>
       </table>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Return multiple Posts as single table’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/return-multiple-posts-as-single-table/#post-9051739)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
