如果我的meta\\u key=\'title\'和meta\\u value=\'my Content Template\'meta\\u key=\'download\\u url\'和meta\\u value=\'http://www.example.com/pdf/pdfinfo.pdf/\'
对于同一篇文章,我有10个元键和元值。如何以表格格式获取所有元信息,例如:
Title URL
My Content http://www.example.com/pdf/pdfinfo.pdf/
Download Data http://www.example.com/pdf/phparray.pdf/
我尝试了以下代码:
<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>
请任何人帮助完成这件事。
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
我不确定这是否是你想要的,但让我试试。。。
<?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>