【问题标题】:Advanced Custom Fields not working for page template高级自定义字段不适用于页面模板
【发布时间】: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


    【解决方案1】:

    调试方法:

    1. 你可以在config.php中开启wp_debug模式

    2. 您可以查看主题文件夹中的error_log文件

    3. 有时您的 acf 字段名长度有问题。

    4. 您可以切换一次主题(回到您的主题)。

    【讨论】:

      猜你喜欢
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      • 2021-06-07
      • 2016-06-28
      • 2021-02-18
      • 1970-01-01
      • 2016-01-15
      相关资源
      最近更新 更多