【发布时间】:2014-03-21 11:50:10
【问题描述】:
我正在创建一系列短代码,这些短代码链接到名为 heroes 的自定义帖子类型上的页面。我想知道如何将我的简码中的信息链接到该自定义帖子类型的帖子,以便我可以将自定义字段数据拉入简码中使用。
这是我正在使用的简码
add_shortcode('illidan', 'illidan');
function illidan($args) {
$default = array('icon' => 'true');
$args = wp_parse_args($args, $default);
$herotip = '';
if ($args['icon']) {
$herotip.= '<img src="http://stormable.com/img/heroes/illidan/illidan-ab1.png">';
}
$herotip.= '<a href="http://stormable.com/heroes/illidan/">Illidan</a>
This is where I would like to pull in custom field data from the post illidan
For example <?php echo get_post_meta($post->ID, "health-lvl1", true); ?>
';
return $herotip;
}
所以在链接下,我希望能够在自定义帖子类型heroes 下的帖子Illidan 中提取自定义字段中的数据,尽管我不确定如何将其链接到该页面.
【问题讨论】:
-
global $post是您访问当前帖子所需的全部内容。 -
谢谢,但问题是这不会出现在当前帖子中,它将是整个网站的其他帖子。
-
然后您需要根据您的要求创建一个新查询,然后执行正常的循环迭代。
if($posts->have_posts(); while($posts->have_posts()): $posts->the_post(); // endwhile; endif; -
如何将其添加到我的简码中?把php直接放进去?
-
所以,
Illidan帖子的 URL 如下:http://stormable.com/heroes/illidan/? URL 会改变吗?还是帖子 ID?
标签: php wordpress custom-fields shortcode