1

How can I get all the meta information of a particular post_id, if my meta_key = 'title' and meta_value = 'My Content Template' meta_key = 'download_url' and meta_value = 'http://www.example.com/pdf/pdfinfo.pdf/'

and i have 10 meta key and meta value for the same post. How can i get all the meta information in a tabular format such as:

Title           URL  
My Content     http://www.example.com/pdf/pdfinfo.pdf/
Download Data   http://www.example.com/pdf/phparray.pdf/

I have tried below code:

<table>
<tr>
    <th>Title</th>
    <th>Download URL</th>
</tr>
<?php 
  $stored_titles = get_post_meta( $post->ID, 'title' );
   $stored_urls = get_post_meta( $post->ID, 'download_url');
?>
<tr>
<?php  foreach($stored_titles as $title) { ?>
<td><?php echo $title; ?></td>
<?php  } ?>
<?php  foreach($stored_urls as $url) { ?>
<td><?php echo $url; ?></td>
<?php  } ?>

</tr>

</table>    

Please any one help to get this done.

1
  • OK, wait... What custom fields exactly are there? Commented Jul 17, 2018 at 15:23

1 Answer 1

0

I'm not sure that this is what you wanted, but let me try...

<?php
    $titles = get_post_meta( $post->ID, 'title' );
    $urls = get_post_meta( $post->ID, 'title' );
?>
<table>
    <thead>
        <tr>
            <th>Title</th>
            <th>Download URL</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ( $titles as $k => $title ) : ?>
        <tr>
            <td><?php echo esc_html($title); ?></td>
            <td><?php echo esc_html( array_key_exists( $k, $urls ) ? $urls[$k] : '' ); ?></td>
        </tr>
    </tbody>
</table>    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.