【问题标题】:Advanced Custom Fields not showing in Custom Post Types UI自定义帖子类型 UI 中未显示高级自定义字段
【发布时间】:2016-06-01 01:11:06
【问题描述】:

在这里提问是因为比 Wordpess 社区的响应率更高。

我设置了一个名为培训服务的自定义帖子类型。我创建了一个名为 content_sn-p 的自定义字段,并将其分配为仅适用于相关的帖子类型。我在帖子类型编辑屏幕上看到该字段并输入一些 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>

【问题讨论】:

    标签: wordpress custom-post-type custom-fields


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多