【问题标题】:Advanced custom fields doesn't show after custom post type, how can I make this work?自定义帖子类型后不显示高级自定义字段,我该如何使其工作?
【发布时间】:2018-10-17 18:08:49
【问题描述】:

我有多个来自高级自定义字段(wordpress 插件)的字段在网站上运行良好。我有 1 种自定义帖子类型,显示效果也很好。问题是在自定义帖子类型之后,我的高级自定义字段字段不再出现。该插件似乎与自定义帖子类型发生冲突。如果我在自定义帖子类型之前发布要显示的字段,它会再次起作用,但这不是一个选项。

    <div class="container-white-bg">
  <div class="columns">
 <?php 
        $query = array (
            'post_type' => 'dates',
            'order' => 'ID',
            'posts_per_page' => 8
        );

        $queryObject = new WP_Query($query);
        if ( $queryObject->have_posts() ): while ( $queryObject->have_posts() ): $queryObject->the_post(); ?>

<a href="" class="price-block w-inline-block">
          <div class="pb-1"></div>
          <div class="datum">
        <?php $begindatum = get_post_meta( $post->ID, 'begindatum', true ); $begindatum = str_replace('(', '<br><span>(', $begindatum); echo str_replace(')', ')</span>', $begindatum); ?>
        <br> - <br>
        <?php $einddatum = get_post_meta( $post->ID, 'einddatum', true ); $einddatum = str_replace('(', '<br><span>(', $einddatum); echo str_replace(')', ')</span>', $einddatum); ?>
        </div>
          <div class="prijs"><?php $price = get_post_meta( $post->ID, 'price', true ); $price = str_replace('(', '<br><span>(', $price); echo str_replace(')', ')</span>', $price); ?></div>
          <div class="periode"><?php $period = get_post_meta( $post->ID, 'period', true ); $period = str_replace('(', '<br><span>(', $period); echo str_replace(')', ')</span>', $period); ?></div>
</a><?php endwhile; endif; ?>
        </div>
    </div>
  </div>
  <div>
    <h2 class="heading">Foto&#x27;s</h2>
        <?php the_field('galerij-homepage'); ?>
  </div>

这是代码。 $query 是我的自定义帖子类型开始的地方。不工作的高级自定义字段是&lt;?php the_field('galerij-homepage'); ?&gt; 我真的被捆绑了,我似乎无法解决这个问题。这是不可能的还是我错过了什么?

【问题讨论】:

  • 在 ACF 字段之前重置查询。
  • 太棒了!如此简单却如此有效。非常感谢,你给我省了很多麻烦! :)

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


【解决方案1】:

在我的评论下发帖的人解决了这个问题。我必须在 ACF 字段之前重置查询。

<?php wp_reset_query(); ?>

仅此而已。

【讨论】:

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