get_post_meta returns "Array"

R3dn0l picture R3dn0l · Oct 9, 2014 · Viewed 10.6k times · Source

I made a very custom meta box. Now im trying to display the data but all I can output is "ArrayArrayArray......" When I var_dump the variable of the array I get the right context but in array style and I need it just like normal text.

Metabox:

add_action('admin_init', 'hhs_add_meta_boxes', 1);
function hhs_add_meta_boxes()
{
    add_meta_box('repeatable-fields', 'Repeatable Fields', 'hhs_repeatable_meta_box_display',                     'category', 'normal', 'default');
    wp_enqueue_script('custom-js', get_template_directory_uri().'/js/custom-js.js');
}

And with this piece of code i display it in the backend. I used several metaboxes but this one feels kinda weird because its not an array like I used before but a table.. (BUT IT WORKS :D )

well its a lot of code so ; http://pastebin.com/k2Mcg6Le

and the save is like this ; http://pastebin.com/CYua3FYM

Might as well give full code now lol.. ; http://pastebin.com/wUG39CCK

Sorry if its full of noob code, im a student :-).

I'm displaying it like this atm:

$metas = get_post_meta($post->ID, 'repeatable_fields', TRUE);
    foreach ( $metas as $metakey ){
        echo $metakey;


    }

Which returns ; ArrayArrayArrayArray.

Since i have 4 fields in the WP editor ; http://i.imgur.com/rnqC5Jp.png

And when i var dump one array I get ;

array(4) { [0]=> array(3) { ["name"]=> string(3) "qwe" ["date"]=> string(10) "qwewerrrrr" ["text"]=> string(10) "qwewerrrrr" } [1]=> array(3) { ["name"]=> string(10) "qwewerrrrr" ["date"]=> string(3) "qwe" ["text"]=> string(10) "qwewerrrrr" } [2]=> array(3) { ["name"]=> string(10) "qwewerrrrr" ["date"]=> string(6) "qweqwe" ["text"]=> string(20) "qwewerrrrrqwewerrrrr" } [3]=> array(3) { ["name"]=> string(6) "qweqwe" ["date"]=> string(13) "qweqwewerrrrr" ["text"]=> string(3) "qwe" } }

I hope i've provided enough information. If more needed, ask please.. really need this fixed so i can finish this project.

Thanks!

Answer

Vignesh Pichamani picture Vignesh Pichamani · Oct 9, 2014

Try this way like

    $metas = get_post_meta($post->ID, 'repeatable_fields', TRUE);
        foreach ( $metas as $metakey ){
            echo $metakey['name'];
            // Similarly for all the fields you want to print
        }