我创建自定义帖子类型“组合”并使用值键“_portfolio_name_value_key”创建自定义元框。但是当我尝试在前端检索保存的值时,它没有显示。
我用这个代码:
单个portfolio.php页面中的 <?php get_post_meta( $post->ID, '_portfolio_name_value_key' ); ?>
,
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<div class=row>
<div class="col-xs-12 col-md-8 col-sm-8">
<div class="owl-carousel owl-theme project-detail-carousel"id=project_detail>
<div class=project-detail-item><img alt=p-detail src="<?php the_post_thumbnail(''); ?>"></div>
</div>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<div class=project-detail-1>
<h2><?php the_title(); ?></h2>
<ul>
<li><span>Client:</span><?php get_post_meta( $post->ID, '_portfolio_name_value_key' ); ?>
<li><span>Category:</span> <?php the_terms( $post->ID, 'field' ); ?>
<li><span>Status:</span> <?php get_post_meta( $post->ID, '_portfolio_status_value_key' ); ?>
<li><span>Tags:</span> <?php the_terms( $post->ID, 'ptag' ); ?>
<li><span>Date:</span> <?php get_post_meta( $post->ID, '_portfolio_date_value_key' ); ?>
</ul>
</div>
</div>
</div>
<div class="row mt-50">
<div class=col-md-12>
<div class=project-detail-1-info>
<h3>A little About This Project</h3>
<div class=text-content>
<?php the_content(); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
答案 0 :(得分:0)
因为看起来你正在使用循环。在循环中,您应该使用get_the_ID()
函数。
发件人:强>
<?php get_post_meta( $post->ID, '_portfolio_name_value_key' ); ?>
要强>
<?php get_post_meta(get_the_ID(), '_portfolio_name_value_key' ); ?>
答案 1 :(得分:0)
试试这个: -
LinearRegression()
答案 2 :(得分:0)
get_post_meta()
返回一个值而不是回显它。
所以你需要像这样回显它:
<?php echo get_post_meta( get_the_ID(), '_portfolio_date_value_key' ,true ); ?>