自定义帖子类型中未显示高级自定义字段UI
问题描述:
由于比Wordpess社区更好的响应率而在此处询问。自定义帖子类型中未显示高级自定义字段UI
我设置了一个名为Training Services的自定义帖子类型。我创建了一个名为content_snippet的自定义字段,并将其分配为仅适用于相关的帖子类型。我在帖子类型编辑屏幕上看到了该字段,并输入了一些Lorem ipsum。
我的代码实现如下(content-page.php):为什么帖子类型的标题,内容和缩略图显示在前端而不是自定义字段?它只是显示一个空的标签,如果我在chrome开发工具中查看它,lorem应该是。
在此先感谢您的帮助!
<!-- Custom Fields
================================================== -->
<?php
$content_snippet = get_field('content_snippet');
?>
<section class="container-fluid section-spacing" style="border:1px solid black;">
<div class=" text-align-center row" style="border:1px solid green;">
<h1><?php the_title(); ?></h1>
<hr class="headingUnderline">
<div class="responsiveShrink" style="border:1px solid yellow;"><?php the_content() ; ?></div>
<?php $loop = new WP_Query(array('post_type' => 'training_services', 'orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while($loop->have_posts()) : $loop->the_post(); ?>
<div class="text-align-center col-xs-12 col-sm-6" style="border:1px solid red;">
<div class="postWrapper">
<div class="imageWrapper">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
</div>
<div class="postContentWrapper">
<h3><?php the_title(); ?></h3>
<div><?php echo $content_snippet; ?></div>
<div><?php the_content(); ?></div>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</section>
答
愚蠢的错误。自定义字段必须在循环内声明。留给未来的读者。