Eleandro Duzentos
Eleandro Duzentos

Reputation: 1548

Advanced Custom Fields not working for page template

I'm building a WordPress theme that has a Homepage template and I'm using ACF for custom fields.

The ACF config is set to allow the fields for pages using the homepage-template.php, but for some reason the get_field($fieldname) is returning NULL and the the_field() doesn't show nothing, even passing the second argument $post_id.

This is the simple code version of the template that is not working:

<?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(); ?>

Upvotes: 0

Views: 2227

Answers (1)

Samyappa
Samyappa

Reputation: 531

Debug Method:

  1. you can enable wp_debug mode in config.php

  2. you can check error_log file on theme folder

  3. some time your acf fieldname length has problem.

  4. you can switch over theme once(back to your theme).

Upvotes: 1

Related Questions