$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'); ?>plugins - Getting value from Advanced Custom Fields|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)

plugins - Getting value from Advanced Custom Fields

matteradmin9PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I'm using the Advance Custom Fields plugin in my WordPress website. I have created a template page and set it for home page. In ACF plugin I created a new Field Group called Travel Form and in it a field called locations. please check below screenshot

In my template I'm calling it by name locations throught ACF function but I'm not able to fetch it.

this is my code

 <?php
    /*
  Template Name: Home Page
  */
  $field = get_field_object('locations');
  print_r($field); die;
 ?>

Where is my mistake? Please tell me. I'm not able to get all locations.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I'm using the Advance Custom Fields plugin in my WordPress website. I have created a template page and set it for home page. In ACF plugin I created a new Field Group called Travel Form and in it a field called locations. please check below screenshot

In my template I'm calling it by name locations throught ACF function but I'm not able to fetch it.

this is my code

 <?php
    /*
  Template Name: Home Page
  */
  $field = get_field_object('locations');
  print_r($field); die;
 ?>

Where is my mistake? Please tell me. I'm not able to get all locations.

Share Improve this question edited Jan 14, 2019 at 21:21 RiddleMeThis 3,8078 gold badges22 silver badges30 bronze badges asked Jan 11, 2019 at 13:23 user158807user158807 112 bronze badges 2
  • 1 If you want to get the selected value for the locations field the correct function is just get_field( 'locations' ); not get_field_object(). – Jacob Peattie Commented Jan 11, 2019 at 14:08
  • 1 Can you explain whether you're wanting to display the select field with all the options, so the user can choose on the homepage itself - or whether you are setting the value in wp-admin and just want to display the selected value on the homepage? – WebElaine Commented Jan 11, 2019 at 14:42
Add a comment  | 

1 Answer 1

Reset to default 1

You are trying to use get_field_object, which isn't correct.

What you should be using is get_field() or the_field().

Example get_field():

$value = get_field( "locations" );

if( $value ) {
    echo $value;
} else {
    echo 'empty';
}

Example the_field():

<p><?php the_field('locations'); ?></p>

Note: ACF has great documentation, you should look it over.

Post a comment

comment list (0)

  1. No comments so far