Support

Account

Home Forums General Issues get_fields() only returning the first field correctly

Unread

get_fields() only returning the first field correctly

  • Running into something a bit weird: When I try to get all the fields like so: $fields = get_fields() and print_r out the results, I’m getting all the values as I would expect from the first field, but the rest aren’t returning any of the values. In addition, the ones without values are also including the field key value, which (I think) the get_field() function isn’t supposed to do. In the scenario below, the amenities field is returning everything correctly but the rates field should have a value of “Our Rates” for the “heading” subfield.

    Array(
      [amenities] => Array(
        [0] => Array(
          [heading] => Our Amenities
          [content] => Lorem ipsum
          [media] =>
        )
      )
      [rates] => Array(
        [0] => Array(
          [field_53f3e1dd3f758] => Rates
          [field_53f3e1ea3f759] => 
          [field_53f3e1f03f75a] => 
          [heading] => 
          [rates] => 
        )
      )
      ...
    )

    What’s even weirder is that I can explicitly pull out a specific field with $field = $get_field('rates') as long as I request that before the get_fields() function. If I do so after get_fields(), it returns the same weird info as above.

    This works:

    
    $field = get_field('rates');
    var_dump($field);
    $all_fields = get_fields();

    But this doesn’t:

    $all_fields = get_fields();
    $field = get_field('rates');
    var_dump($field);
Viewing 1 post (of 1 total)

The topic ‘get_fields() only returning the first field correctly’ is closed to new replies.