我为我的投资组合页面创建了一个自定义帖子类型。我有两个自定义字段:
- 产品网址
- 案例研究网址
我的问题是在我的主题中使用这些自定义字段的值。目前我通过运行这个来获取它们的值:
<?php
$loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 3));
while ( $loop->have_posts() ) : $loop->the_post();
$custom = get_post_custom($post->ID);
$product_url = $custom['product_url'];
foreach ($product_url as $key => $value)
echo $key . " => " . $value . "<br />";
$custom = get_post_custom($post->ID);
$case_study_url = $custom['case_study_url'];
foreach ($case_study_url as $key => $value)
echo $key . " => " . $value . "<br />";
?>
// All my mark-up
<?php endwhile; ?>
如果我的术语在这里有意义,我想知道,但有没有办法我可以运行 foreach 循环,以便它显示 product_url 和 case_study_url?
在此先感谢您的帮助。
真挚地。