$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - ACF not showing|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - ACF not showing

matteradmin11PV0评论

I have a (weird) issue - can't get the ACF field to work on my page. I have a simple text_field and it shows on the Homepage page section:

ACF settings:


Homepage settings (when I refresh the panel it shows Lorem ipsum so it's saved in the databse):

And in my index.php page I have:

<?php
  $hero = the_field('hero_title');
  /* tried also  */
  /* $hero = get_field('text_field'); */

  echo '<h1>'.$hero.'</h1>';
?>

Where it shows the blank <h1></h1> on my page:

What am I doing wrong? I also tried with group type and I have the same issue.

I have a (weird) issue - can't get the ACF field to work on my page. I have a simple text_field and it shows on the Homepage page section:

ACF settings:


Homepage settings (when I refresh the panel it shows Lorem ipsum so it's saved in the databse):

And in my index.php page I have:

<?php
  $hero = the_field('hero_title');
  /* tried also  */
  /* $hero = get_field('text_field'); */

  echo '<h1>'.$hero.'</h1>';
?>

Where it shows the blank <h1></h1> on my page:

What am I doing wrong? I also tried with group type and I have the same issue.

Share Improve this question edited Feb 1, 2019 at 8:09 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Feb 1, 2019 at 8:03 VuckoVucko 1631 gold badge1 silver badge10 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

the_field() function shows the value and it doesn't get/return anything. Like the_title() and other template tags starting with the_.

It means that:

This line prints the value and $hero variable is empty.

$hero = the_field('hero_title');

This line prints only <h1> tags.

echo '<h1>'.$hero.'</h1>';

What you want is:

echo '<h1>' . get_field('hero_title') . '</h1>';

Try

$hero = get_field('hero_title');

Instead of

$hero = the_field('hero_title');

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far