WordPress的ACF get_field()不返回值 [英] Wordpress ACF get_field( ) not returning value

查看:252
本文介绍了WordPress的ACF get_field()不返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Wordpress 中使用高级自定义字段插件。我在页面上显示字段时遇到困难。

I am using the advanced custom field plugin for Wordpress. I am having difficulty displaying a field on my page.

基本上,我已经创建了一个字段组,并将 id c分配给了该组的成员。然后,我使用 get_field('field_name')函数将该字段的值存储在变量中,然后 echo 屏幕上。但是,这将返回 false

Basically I've created a field group and assigned id's to the members of that group. I then use the get_field('field_name') function to store the value of this field in a variable and echo it on the screen. However this is returning false.

我也尝试过使用 the_field('field_name'),但这返回 null 。然后,我在某处阅读如果您尝试访问Wordpress循环之外的字段,则必须将 post id 作为参数传递给 get_field() / the_field()方法。

I've also tried using the_field('field_name') but this returns null. I then read somewhere If you are trying to access a field outside of the Wordpress loop you must pass the post id as a parameter to the get_field()/the_field() methods.

我已经尝试过了,但结果仍然相同...有人对这是什么有任何想法吗?问题?

I've tried that and still the same result...Does anyone have any idea as to what is the problem?

这是我的代码:

<?php get_header();
      $postID = get_the_ID();
      the_field('the-title', $postID); //Nothing being returned...
      die(); 
?>


推荐答案

如果您使用的是 WP_Query()在使用 get_field()之前,需要使用 wp_reset_query()功能。我希望它能解决这个问题。

If you're using WP_Query() before using get_field(), you need to reset the query using wp_reset_query() function. I hope it'll solve this issue.

这篇关于WordPress的ACF get_field()不返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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