Home Forums General Issues preload a select field with value and label


preload a select field with value and label

  • What I am trying to do is preload a select field with a value and a label from two different acf form fields on a CPT. What I have is working very well but it only adds the value. I need help on how I add the label to the return.

    Here is what I have:

    function my_acf_load_field( $field )
      $field['choices'] = array();
      $staff_post_ids = get_posts(array(
          'post_type'     => 'nurse',
          'numberposts'   => -1, // get all posts.
          'fields'        => 'ids', // Only get post IDs
      foreach($staff_post_ids as $staff_id){
          $staff_email = get_field('staff_email_address', $staff_id);
           $field['choices'][$staff_email] = $staff_email;
      return $field;

    Can someone please help or guide me on how to get the post title and add it to this code as the label? I have tried many times but to no avail. Please help!

    Here is a code example of what I am trying to add:
    $staff_title = get_the_title( $label);

    Thank you in advance…

  • Gentle Bump, Please Help!

    $field['choices'][$staff_email] = get_the_title($staff_id);
  • Thank you, That did it. Your help is very much appreciated.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘preload a select field with value and label’ is closed to new replies.