谁能发现为什么我的Wordpress循环会破坏其后的所有“高级自定义字段”代码? [英] Can anyone spot why my Wordpress loop breaks all the Advanced Custom Fields code that comes after it?

查看:59
本文介绍了谁能发现为什么我的Wordpress循环会破坏其后的所有“高级自定义字段”代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下循环正在成功运行,并且在我的编辑器中未显示语法错误,但是它仅破坏了其后的Advanced Custom Fields PHP(之前的所有ACF正常运行,而除了ACF之后的所有正常运行)。 / p>

The following loop is running successfully and shows no syntax error in my editor, but it's breaking only the Advanced Custom Fields PHP that comes after it (all the ACF before it works fine, and everything after except ACF works fine).

<?php
    $args=array(
        'post_type' => 'page',
        'post_parent' => '39'
    );

    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

    <div class="project" style="background-image:url('<?php the_field('preview_thumbnail'); ?>')">
        <div class="project-overlay" style="background-color:<?php the_field('project_highlight_color'); ?>">
        </div>
        <div class="project-content">
            <h3><?php the_title(); ?></h3>
            <p><?php the_field('preview_text'); ?></p>
            <a href="<?php the_permalink(); ?>" class="button arrow-right">Read more</a>
        </div>
    </div>

<?php endwhile; } ?>

下面是一个例子,说明它仍然有效

< img src =<?php echo get_template_directory_uri();?> /images/logo-white.png />

Here's an example of what still works after it
<img src="<?php echo get_template_directory_uri(); ?>/images/logo-white.png" />

这是一个示例,介绍了后面的内容(高级自定义字段代码)

< p class = banner-text><?php the_field(' pullout_summary'); ?>< / p>

And here's an example of what's breaking after it (Advanced custom fields code)
<p class="banner-text"><?php the_field('pullout_summary'); ?></p>

抱歉,这是公然的解决方法!

Sorry if it's a blatant fix! Thanks in advance.

推荐答案

自定义查询后,您需要恢复全局 $ post 变量为 wp_reset_postdata()食典中的更多信息。

After a custom query, you need to restore the global $post variable of the main query with wp_reset_postdata(). More info in the Codex.

这篇关于谁能发现为什么我的Wordpress循环会破坏其后的所有“高级自定义字段”代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆