plugins - Getting value from Advanced Custom Fields

admin2025-06-04  9

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749012386a315607.html

最新回复(0)