0

firstly i created a select dropdownlist using acf that dynamically populate like this:

add_filter('acf/load_field/name=chef', 'my_acf_load_chef_field');

function my_acf_load_chef_field( $field )
{    
    $user_fields = array( 'user_login');
    $argu = new WP_User_Query( array( 'role' => 'chef' , 'fields' => $user_fields ));
    $choices = $argu->get_results();
    //$choices = get_field($field['choices'], $post->ID , false);
    $field['choices'] = array();  
     if( is_array($choices) ) {
        $len = count($choices);
        for($i = 0; $i < $len; $i++) {
            array_push($field['choices'], ($choices[$i]->user_login));
    }
   }
    return $field;

and it worked well in retrieving data but when i select the wanted chef it save my ACF key instead of the value in post meta value field_5cf49fa0651bb like this

i want to insert the selected value in mysql

  • Can you give an example. I don't understand what you mean with ACF key. Give me an example of the array $choices and give me an example of the desired result. Add them both to your question, not in comments please. – Refilon Jun 19 at 10:05
  • my example is written in this link stackoverflow.com/questions/55982412/… now i already get the choices in my select menu from users that have a chef role but in mysql when i'm tried to get the values of my advanced custom field (ACF) to make the user select his chef to make order the meta value is written as a my custom field key field_5cf49fa0651bb not the selected chef – Moamen Khedr Jun 19 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.