• Resolved gleenk

    (@gleenk)


    Hi, i need a quick example on how to get current post custom field. I have a custom field array but when i create my filter i always get key value (1,2,3) instead of array value:

    
    function cf7_dynamic_select_do_example1($choices, $args=array()) {
        $choices = get_field('prod_esecuzione');
        return $choices;
    } 
    add_filter('fi-dyn-esecuzione', 'cf7_dynamic_select_do_example1', 10, 2);
    

    I always get 0,1,2,3 instead of value

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Huebner

    (@hube2)

    What type of ACF field are you using there and what do you have the return set to?

    My guess is that it is returning an array of value => label pairs and this plugin requires them as label => value pairs. (The reason that I’ve done this is to allow multiple labels to have the same value.)

    I would try

    
    $choices = array_flip(get_field('prod_esecuzione'));
    
    Thread Starter gleenk

    (@gleenk)

    I’m using a checkbox field! And your trick works! 🙂

    PS: is it possible to have a blank value as first one?

    • This reply was modified 8 years, 11 months ago by gleenk.
    • This reply was modified 8 years, 11 months ago by gleenk.
    Plugin Author John Huebner

    (@hube2)

    Yes

    
    $choices = array('-- Make a Selection --' => '');
    $choices = array_merge($choices, array_flip(get_field('prod_esecuzione')));
    
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get custom field value list’ is closed to new replies.