开发者

PHP Printing a variable from an array of meta keys in WordPress

I'm trying to print the 'artistName' meta keys in a list from the following array:

$postID =开发者_StackOverflow社区 $post->ID;
$meta = get_post_meta($postID, $_artistMeta->$postID, TRUE);
print_r($meta);

(which prints the following)

   Array
    (
        [_artistMeta] => Array
            (
                [0] => a:1:{s:10:"artistName";a:2:{i:0;s:33:"la-semilla-de-la-cultura-africana";i:1;s:9:"radiohead";}}
            )
    )

So I want to print/echo the artist names ("la-semilla-de-la-cultura-africana" and "radiohead")... I tried the following two:

foreach ($meta['artistName'] as $artist) {
     echo $artist;
}

which prints nothing... OR

foreach ($meta['_artistMeta'] as $artist) {
     echo $artist['artistName'];
}

which prints "a".

If you can help me with the syntax here, I'd really appreciate it! Thanks!


you should use unserialize to get back a php array

$postID = $post->ID;
$meta = get_post_meta($postID, $_artistMeta->$postID, TRUE);
$artists = unserialize($meta['_artistMeta'][0]);
foreach ($artists['artistName'] as $artist)
{
     echo $artist;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜