$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - Displaying posts inside table having issues|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - Displaying posts inside table having issues

matteradmin8PV0评论

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

Post a comment

comment list (0)

  1. No comments so far