高级自定义字段未显示在自定义帖子类型UI中

问题描述 投票:0回答:1

在这里问,因为比Wordpress社区更好的响应率。

我设置了一个名为Training Services的自定义帖子类型。我创建了一个名为content_snippet的自定义字段,并将其指定为仅应用于相关的帖子类型。我在帖子类型编辑屏幕上看到该字段并输入一些lorem ipsum。

我的实现代码如下(content-page.php):为什么帖子类型的标题,内容和缩略图显示在前端而不是自定义字段?如果我在chrome dev工具中查看它,它只显示一个空标记,其中应该是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>
wordpress custom-post-type custom-fields
1个回答
0
投票

愚蠢的错误。必须在循环内声明自定义字段。将此留给未来的读者。

© www.soinside.com 2019 - 2024. All rights reserved.