使用foreach和Wordpress进行未定义的索引


Undefined index using foreach with Wordpress

好吧,我漫长的一天正赶上我……我正试图列出自定义的post元字段,并不断得到注意:未定义的索引:…中的相关标题数组如下:

Array ( [0] => Array ( [0] => Array ( [related-headline] => Street Outlaws Turbo Rotary Mazda RX-7 – OKC NoPrep [related-url] => //localhost:3000/street-outlaws-turbo-rotary-mazda-rx-7-okc-noprep/ [related-image_id] => 78055 [related-image] => //localhost:3000/wp-content/uploads/2015/12/lucky-to-be-alive-distracted-dri.jpg ) [1] => Array ( [related-headline] => In the Driver’s Seat: Shane vs. The Reaper | Street Outlaws [related-url] => //localhost:3000/in-the-drivers-seat-shane-vs-the-reaper-street-outlaws/ [related-image_id] => 78048 [related-image] => //localhost:3000/wp-content/uploads/2015/12/ford-f350-vs-dodge-ram-vs-chevy.jpg ) ) ) 

这是我的代码:

$entries = get_post_meta( get_the_ID(), 'ss-related-posts' );
// print_r($entries);
foreach ( (array) $entries as $key => $entry ) {
    $title = '';
    $title = $entry['related-headline'];
    echo $title;
}

我知道我在这里错过了一些简单的东西,所以任何帮助都将不胜感激。

我通过简单地将TRUE添加到cale_b:的注释中所建议的函数调用中来实现它

$entries = get_post_meta( get_the_ID(), 'ss-related-posts', TRUE );
foreach ( (array) $entries as $key => $entry ) {
    $title = $url = $img = "";
    $title = $entry['related-headline'];
    $url = $entry['related-url'];
    $img = $entry['related-image'];
    echo $title . "<br>" . $url . "<br>" . $img . "<br>";
}