customization - Displaying posts inside table having issues

admin2025-06-04  0

I am trying to create a comparsion table like the attached image. But it was not working like in the image.

for that i have done following code what i am getting is not like the image for example the word at the left BED it was repeating several times i need it only at the beginning. It needs to be shown only once.

<?php 
$args = array(
'post_type'=> 'forsale',
'p' =>         '12,16',
'orderby'    => 'ID',
'post_status' => 'publish',
'order'    => 'DESC',
'posts_per_page' => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>

<table class="container">

<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<thead><tr><th><?php the_title(); ?></th></tr></thead>   
<tbody>
<tr><td>Price</td><td><?php echo get_post_meta( get_the_ID(), 'price' ); ?></td><tr>
<tr><td>Bed</td><td><?php echo get_post_meta( get_the_ID(), 'bed' ); ?></td><tr>
</tbody>
<?php endwhile; ?>
</table>
<?php endif;
wp_reset_postdata(); ?>

I am trying to create a comparsion table like the attached image. But it was not working like in the image.

for that i have done following code what i am getting is not like the image for example the word at the left BED it was repeating several times i need it only at the beginning. It needs to be shown only once.

<?php 
$args = array(
'post_type'=> 'forsale',
'p' =>         '12,16',
'orderby'    => 'ID',
'post_status' => 'publish',
'order'    => 'DESC',
'posts_per_page' => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>

<table class="container">

<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<thead><tr><th><?php the_title(); ?></th></tr></thead>   
<tbody>
<tr><td>Price</td><td><?php echo get_post_meta( get_the_ID(), 'price' ); ?></td><tr>
<tr><td>Bed</td><td><?php echo get_post_meta( get_the_ID(), 'bed' ); ?></td><tr>
</tbody>
<?php endwhile; ?>
</table>
<?php endif;
wp_reset_postdata(); ?>
Share Improve this question edited Jan 18, 2019 at 18:13 James Paul asked Jan 17, 2019 at 18:25 James PaulJames Paul 3711 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
Bed

On the above line you are missing echo before get_post_meta function thats why it is only showing Bed for all the entries.

Please change the above code with the below code that has echo before the get_post_meta function. Bed

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748996575a315476.html

最新回复(0)