Custom post type 获取与显示帖子不同的一种帖子类型的帖子
我正在寻找从一个不同于显示帖子的帖子类型中获取“get_post_meta”? 这是我的代码,但它显示了post类型中所有post的post_meta! 我想这可能是比较谁的职位有相同的鼻涕虫(职位名称),但我不知道怎么做Custom post type 获取与显示帖子不同的一种帖子类型的帖子,custom-post-type,wordpress,Custom Post Type,Wordpress,我正在寻找从一个不同于显示帖子的帖子类型中获取“get_post_meta”? 这是我的代码,但它显示了post类型中所有post的post_meta! 我想这可能是比较谁的职位有相同的鼻涕虫(职位名称),但我不知道怎么做 <?php $sectionscontact = new WP_query(array('post_type' => 'sections-contact', 'post_count'=>1));if ($sectionscontact->have_p
<?php $sectionscontact = new WP_query(array('post_type' => 'sections-contact', 'post_count'=>1));if ($sectionscontact->have_posts()): while ( $sectionscontact->have_posts() ) : $sectionscontact->the_post(); $telephone_meta_empty = get_post_meta(451,'telephone', true);
if ( ! empty ( $telephone_meta_empty ) ) { ?>
<div class="tp_titre_bloc" style="border-right:1px solid #999999;"> Téléphone</div>
<div class="tp_content_bloc">
<?php echo get_post_meta(get_the_ID(), 'telephone', true); ?>
</div>
<?php } ?>
电话
我在这里所做的就是为您整理一下。
此外,它还显示此帖子类型中所有内容的帖子元,因为您使用的是
post\u count
,而不是posts\u per\u page
,这是在一个查询中显示一定数量帖子的正确术语
因此,与此相反:
<?php
$sectionscontact = new WP_query( array(
'post_type' => 'sections-contact',
'post_count' => 1
));
if ($sectionscontact->have_posts()):
while ( $sectionscontact->have_posts() ) :
$sectionscontact->the_post();
$telephone_meta_empty = get_post_meta(451,'telephone', true);
if ( ! empty ( $telephone_meta_empty ) ) { ?>
<div class="tp_titre_bloc" style="border-right:1px solid #999999;">Téléphone</div>
<div class="tp_content_bloc">
<?php echo get_post_meta(get_the_id(), 'telephone', true); ?>
</div>
<?php } ?>
电话
你想要这个:
<?php
$sectionscontact = new WP_query( array(
'post_type' => 'sections-contact',
'posts_per_page' => 1 //changed post_count to posts_per_page
));
if ($sectionscontact->have_posts()):
while ( $sectionscontact->have_posts() ) :
$sectionscontact->the_post();
$telephone_meta_empty = get_post_meta(451,'telephone', true);
if ( ! empty ( $telephone_meta_empty ) ) { ?>
<div class="tp_titre_bloc" style="border-right:1px solid #999999;">Téléphone</div>
<div class="tp_content_bloc">
<?php echo get_post_meta($post->ID, 'telephone', true); // changed get_the_id() to $post->ID?>
</div>
<?php } ?>
电话
如果有帮助,请告诉我
有关WP_查询的更多信息:
谢谢