Domanda

Sto cercando di stampare il meta key "artistname" in un elenco dal seguente array:

$postID = $post->ID;
$meta = get_post_meta($postID, $_artistMeta->$postID, TRUE);
print_r($meta);

(che stampa quanto segue)

   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";}}
            )
    )

Quindi voglio stampare/far eco ai nomi degli artisti ("La-Semilla-de-la-Cultura-Africana" e "Radiohead") ... Ho provato i seguenti due:

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

che non stampa nulla ... o

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

che stampa "A".

Se puoi aiutarmi con la sintassi qui, lo apprezzerei davvero! Grazie!

È stato utile?

Soluzione

Dovresti usare UnSerialize per recuperare un array PHP

$postID = $post->ID;
$meta = get_post_meta($postID, $_artistMeta->$postID, TRUE);
$artists = unserialize($meta['_artistMeta'][0]);
foreach ($artists['artistName'] as $artist)
{
     echo $artist;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top