Errors with this code, what is wrong?

0
'asset_kind' => function($fields, $id) {

    $kind = get_post_field('asset_content_sections', $id);

    $fields = $kind['radio_kind'];

    return $fields;
},

Some of the errors:

  

Undefined index: radio_kind

     

Illegal string offset 'radio_kind'

     

Uninitialized string offset: 0

Dump of variable $kind :

"asset_kind": [ 
    { 
        "title": "das", 
        "content_blocks": [ 
            { 
                "content": " dsadad \n", 
                "radio_kind": "right" 
            } 
        ] 
    } 
]
    
asked by Santiago D'Antuoni 15.11.2016 в 20:43
source

1 answer

0

You should do something like this:

'asset_kind' => function($fields, $id) {

        $kind = json_decode(get_post_field('asset_content_sections', $id));

        $fields = $kind['content_blocks'][0]['radio_kind'];

        return $fields;
    },

That helps you get to the key you want, remember that I'm accessing 0 because it's an array.

    
answered by 15.11.2016 в 21:14