duan201444 2015-11-13 17:45
浏览 83
已采纳

运行循环后ACF未显示

In the below code, I call fields from Advanced Custom Fields plugin and only the first two show 'home_title' and 'home_content'. After these two I run two different loops to show the latest posts in a given category. After those loops run there are 4 more fields from ACF called. 'donate_title' , 'donate_content' , 'mission_title' , 'mission_content'. Which are not showing up (not pulling any content at all).

If I move these ACF before running the loops they all show up correctly. So I imagine there is a problem with these following the loops but cannot find the reason.

<div class="main-site">
<div class="home-title-1">
<?php the_field('home_title'); ?>
</div>
<div class="home-content-1">
<?php the_field('home_content'); ?>
</div>

<div class="home-boxes-cont">
<div class="box-left">
<?php
query_posts('cat=4&posts_per_page=1');
while (have_posts()) : the_post(); ?>
    <div class="bl-img">
    </div>
    <div class="bl-title">
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
    <div class="bl-content">
    <?php the_excerpt(); ?>
    </div>
<?php endwhile; ?>
</div>

<div class="box-middle">
<?php
query_posts('cat=5&posts_per_page=1');
while (have_posts()) : the_post(); ?>
    <div class="bm-img">
    </div>
    <div class="bm-title">
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
    <div class="bm-content">
    <?php the_excerpt(); ?>
    </div>
<?php endwhile; ?>
</div>

<div class="box-right">
    <div class="br-img">
    </div>
    <div class="br-title">
    <?php the_field('donate_title'); ?>
    </div>
    <div class="br-content">
    <?php the_field('donate_content'); ?>
    </div>
</div>
</div>

<div class="mission-title">
    <?php the_field('mission_title'); ?>
</div>
<div class="mission-content">
    <?php the_field("mission_content"); ?>
</div>
  • 写回答

3条回答 默认 最新

  • doucheyi1347 2015-11-13 21:31
    关注

    In order to get custom field data from the original post after altering the global post data with your query_posts() calls, you need to reset your post data with the wp_reset_query() function. Place this function after each loop -

    <?php while (have_posts()) : the_post(); ?>
    
    ...
    
    <?php endwhile; wp_reset_query(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了