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

enter image description here

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

  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.

put on hold as off-topic by Milo, Jacob Peattie, shanebp, rudtek, Howdy_McGee 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Jan 11 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 Jan 11 at 14:42

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.