Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to populate a ACF select field with an array from a custom $wpdb->get_results call, which is essentially a list of categories from my db.

I have the following:

global $wpdb;
$wpdb->show_errors();

$myArray = $wpdb->get_row("SELECT cat_name FROM wp_wpfb_cats WHERE cat_parent = '0'", ARRAY_A); 

if(function_exists("register_field_group"))
{
    register_field_group(array (
        'id' => '5040bc74e47c3',
        'title' => 'Folder Name',
        'fields' => 
        array (
            0 => 
            array (
                'key' => 'field_503e2aef44bc0',
                'label' => 'My Label',
                'name' => 'my_label_name',
                'type' => 'select',
                'instructions' => '',
                'required' => '1',
                'choices' => array ( 
                        $myArray 
                    ),
                'default_value' => '',
                'allow_null' => '0',
                'multiple' => '0',
                'order_no' => '0',
            ),
        ),
        'location' => 
        array (
            'rules' => 
            array (
                0 => 
                array (
                    'param' => 'post_type',
                    'operator' => '==',
                    'value' => 'clientspage',
                    'order_no' => '0',
                ),
            ),
            'allorany' => 'all',
        ),
        'options' => 
        array (
            'position' => 'normal',
            'layout' => 'default',
            'hide_on_screen' => 
            array (
            ),
        ),
        'menu_order' => 0,
    ));
}

How can I go about pushing my results into this ACF select field? I currently get:

This 'Array'

share|improve this question
    
register_field_group is not a Wordpress function. What (plugin) defined it? –  janw Aug 31 '12 at 14:25
    
Advanced Custom Fields –  SMacFadyen Aug 31 '12 at 14:29
add comment

1 Answer

Your $wdpb call is already returning an array, so you shouldn't need to wrap it in another array in ACF (inside the choices array). For example, this is what ACF is expecting:

array(
    'choices' =>
        array (
        'test1' => 'Test',
        'test2' => 'Test 2',
        'test3' => 'Test 3'
    ),
),
share|improve this answer
    
Did the above help? –  Zach Nov 1 '12 at 20:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.