Support

Account

Home Forums Front-end Issues Get Select Field Options Reply To: Get Select Field Options

  • Theory: $field is blank for the same reason as the starting issue – that, until a field value is actually saved, the object does not actually have a field value obtainable by its name (?). And it will actually be impossible for me to programmatically obtain a field key using a field name, until that field is actually saved with some values? Am I right/wrong?

    Assuming that’s right, okay, I’ll bow to hard-code the field keys instead…

               // Convert Json
               $json_object = json_decode($json_result_string);
    
               // SAVE TO ACF GROUP:
    
               // Categories (source stdClass object):
    
               // sector
              $field_key = 'field_5c1bb19b00004';
              update_field($field_key, $json_object->category->sector, $org_id_prefixed);
    
              // industryGroup
              $field_key = 'field_5c1bb1f100005';
              update_field($field_key, $json_object->category->industryGroup, $org_id_prefixed);
    
              // industry
              $field_key = 'field_5c1bb36d55bf7';
              update_field($field_key, $json_object->category->industry, $org_id_prefixed);
    
              // subIndustry
              $field_key = 'field_5c1bb474dfb1a';
              update_field($field_key, $json_object->category->subIndustry, $org_id_prefixed);
    
              // sicCode
              $field_key = 'field_5c1bb495dfb1b';
              update_field($field_key, $json_object->category->sicCode, $org_id_prefixed);
    
              // naicsCode
              $field_key = 'field_5c1bb4bddfb1c';
              update_field($field_key, $json_object->category->naicsCode, $org_id_prefixed);
    
              // Tags (source Array):
              $field_key = 'field_5c0a9d251831a';
              update_field($field_key, $json_object->tags, $org_id_prefixed);

    For a test, I have wiped the pre-fixed “Choices” out of all fields in the field group editor, and re-saved the group. Also, I have run this code on a taxonomy term which has not previously had any of the values set. The outcome is this…

    That is, the values are saving to the fields, but still not in the way intended re: cementing Choices as per my original problem. Only the values for the “Tags” Checkbox field have been set as Choices, the rest have not…

    One thing that’s noticeable (this may be coincidence, or not) is that the source for “Tags” is an array from the Json (“tags”), whilst the source for the rest of the values is a “std Class Object”. See the red/green rectangles in each of the screengrabs…

    Any correlation in this discrepancy, or am I already doing things correctly?