Wordpress get_post_meta无效

时间:2015-03-27 16:15:15

标签: php wordpress custom-fields

我正在尝试在wordpress中添加一些自定义字段,但我遇到了问题。我有4个不同的领域(房间,人,浴室,表面),我正在使用的代码是下面的,问题是只显示第一个字段的值,而其他三个我只是得到标题( ex。房间:10,人:,浴室:,表面:,)。你能告诉我我做错了什么吗? 提前谢谢大家。

    <?php if ($accommodation_location != null) { ?>
    <div class="price">
    <?php _e('Rooms: ', 'bookyourtravel'); ?> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta(get_the_ID(), 'accommodation_max_rooms', true); wp_reset_query(); ?>
   <br/><?php _e('Persons: ', 'bookyourtravel'); ?> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta(get_the_ID(), 'accommodation_max_person_count', true); wp_reset_query(); ?>
   <br/><?php _e('Bathrooms: ', 'bookyourtravel'); ?> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta(get_the_ID(), 'accommodation_max_bathrooms', true); wp_reset_query(); ?>
   <br/><?php _e('Surfase: ', 'bookyourtravel'); ?> <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta(get_the_ID(), 'accommodation_max_sqmtot', true); wp_reset_query(); ?> <?php _e('m2', 'bookyourtravel'); ?>
    </div>
    <?php } ?>

1 个答案:

答案 0 :(得分:0)

我自己找出解决方案。我发布它以防将来有人需要它!

<?php if ($accommodation_location != null) { ?>
<div>
    <?php _e('Rooms: ', 'bookyourtravel'); ?><?php echo $accommodation_obj->get_custom_field('max_rooms'); ?>
       <br/><?php _e('Persons: ', 'bookyourtravel'); ?><?php echo $accommodation_obj->get_custom_field('max_person_count'); ?>
       <br/><?php _e('Bathrooms: ', 'bookyourtravel'); ?><?php echo $accommodation_obj->get_custom_field('max_bathrooms'); ?>
       <br/><?php _e('Surfase: ', 'bookyourtravel'); ?><?php echo $accommodation_obj->get_custom_field('max_sqmtot'); ?><?php _e('m2', 'bookyourtravel'); ?>
</div>