【问题标题】:Display metabox values in Wordpress在 Wordpress 中显示元框值
【发布时间】:2013-12-16 16:52:22
【问题描述】:

我正在尝试在 Wordpress 中添加带有日期的元框。我使用了来自this page 的代码。它运行良好,但我在页面上显示元框值时遇到问题。

我的循环:

<?php query_posts(array('post_type' => 'event' , 'posts_per_page' => 9999, 'orderby' => 'menu_order', 'order' => 'ASC' ));
if (have_posts()) : while (have_posts()) : the_post();
$custom = get_post_custom($post->ID); ?>

<div class="event">
    <h2><?php the_title(); ?></h2>
    <p>Date: <?php echo get_post_meta($post->ID, '_day', true);?>.<?php echo get_post_meta($post->ID, '_month', true);?>.<?php echo get_post_meta($post->ID, '_year', true);?></p>
    <p>Hour: <?php echo get_post_meta($post->ID, '_hour', true);?>:<?php echo get_post_meta($post->ID, '_minute', true);?></p>
    <?php the_content(''); ?>
</div>
<?php endwhile; endif; ?>

我添加了自定义帖子类型“事件”。 metabox(date/location) 中的值已保存,但尚未显示在页面上。

为什么它不起作用?

【问题讨论】:

  • 嘿,你编辑了你的帖子,而我同时发布了答案
  • 对不起,我不知道。我已被编辑,因为我看到代码中的错误可以忽略不计。

标签: php wordpress custom-post-type


【解决方案1】:

问题解决了。我写的 meta_key 不正确。

例如:

而“_day”必须是“_start_day”(开始日)或“_end_day”(结束日)

使用 Start Day 显示元框的正确代码:

<?php echo get_post_meta($post->ID, '_start_day', true);?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2018-07-22
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    相关资源
    最近更新 更多