I needed to display some data in a simple html table so I started with very basics of table. As shown in the code, the data needed was a list of custom-field-values of a meta_key submitdate, from across all the posts, under a specific tag "female". I wrote the following code and everything worked perfectly till the first
UPDATE : Current code as suggested by @islam.
<table border="1"> <thead> <tr> <th>NO.</th> <th>FEMALE DATA</th> <th>MALE DATA</th> </tr> </thead> <tbody> <?php $fmargs = array ( 'tag' => 'female', 'posts_per_page' => -1 ); $female_query = new WP_Query( $fmargs ); while ( $female_query -> have_posts() ): $female_query -> the_post(); ?> <tr> <td></td> <td> <?php echo get_post_meta($post->ID, 'submitdate', true); ?> </td> <?php endwhile; wp_reset_postdata(); //reset the first query ?> <?php $margs = array ( 'tag' => 'male', 'posts_per_page' => -1 ); $male_query = new WP_Query( $margs ); while ( $male_query -> have_posts() ): $male_query -> the_post(); ?> <td> <?php echo get_post_meta($post->ID, 'submitdate', true);?> </td> </tr> <?php endwhile; wp_reset_postdata(); //reset the second query ?> </tbody> </table>
Now, I needed a list of data filled in similar way into second column in the same table for another tag "male". When I tried a second similar
WP_Query, it returns the data but it either fills up into the wrong row or a single cell or completely breaks out of table. as I tried endless varieties of
<tr> and <td> . So, I am unable to get the data listed into the second column exactly as the first column.
After writing so far I just realized that this question could be categorized as non-wordpress issue, so if you feel I should definitely ask it somewhere, Please let me know, else a little helping hand is always appreciated. Here is a screenshot of the current result. Please help.