【发布时间】:2019-10-04 00:18:31
【问题描述】:
我正在构建一个具有主页模板的 WordPress 主题,并且我正在将 ACF 用于自定义字段。
ACF 配置设置为允许使用 homepage-template.php 的页面字段,但由于某种原因,get_field($fieldname) 返回 NULL,而 the_field() 没有显示任何内容,即使传递了第二个参数 @ 987654325@.
这是不工作的模板的简单代码版本:
<?php
/**
* Template Name: Home template
*
* @package Package
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header();
while (have_posts()): the_post();
the_title(); // Works
echo get_the_ID(); // Works
var_dump(get_field('banner-title')); // NULL
?>
<?php
endwhile;
wp_reset_postdata();
?>
<?php get_footer(); ?>
- WordPress:4.9.1
- ACF:5.7.9
【问题讨论】:
标签: templates wordpress-theming advanced-custom-fields