I have a repeatable text field “show_on_pages”, I have created a new post of this content type and added 3 values for “show_on_pages”. When i run the code below
$args = array('post_type' => 'my_post_type');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$meta = get_post_meta(get_the_id(),'show_on_pages');
print_r($meta);
endwhile;
It returns a string and not an array
Array ( [0] => [“page1″,”page2″,”page3”] )
If I do
echo $meta[0];
The page will print “[“page1″,”page2″,”page3″]”
You meta is stored as JSON.
Do the following
$pages=json_decode($meta[0]);
and$pages
will be an array which will look like this (from your example):Refer to this documentation for more info on
json_decode
function.