簡體   English   中英

WordPress的get_post_meta不起作用

[英]Wordpress get_post_meta not working

我正在嘗試在wordpress中添加一些自定義字段,但遇到了問題。 我有4個不同的字段(房間,人,浴室,地面),下面使用的代碼是波紋管,問題是僅顯示第一個字段的值,其他三個我只得到標題(例如:房間: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 } ?>

我自己想辦法。 我正在發布它,以防將來有人需要它!

<?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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM