我在自定义帖子类型的wordpress中有以下多维数组。自定义帖子类型名称为:“参考”
如何获取以下值: reference_page_lead 和 reference_page_url ?
array(4) {
["_edit_last"]=>
array(1) {
[0]=>
string(1) "1"
}
["_edit_lock"]=>
array(1) {
[0]=>
string(12) "1424697906:1"
}
["_reference"]=>
array(1) {
[0]=>
string(189) "a:2:{s:19:"reference_page_lead";s:95:"A Lorem Ipsum egy egyszerû szövegrészlete, szövegutánzata a betûszedõ és nyomdaiparnak.";s:18:"reference_page_url";s:19:"https://lorem.ipsum";}"
}
["_thumbnail_id"]=>
array(1) {
[0]=>
string(2) "36"
}
感谢您的帮助!
答案 0 :(得分:0)
数据已序列化,因此您需要对其进行反序列化。
$result = unserialize($theArray["_reference"][0]);
echo $result['reference_page_url'];
echo $result['reference_page_lead'];
答案 1 :(得分:0)
$reference_data = get_post_meta( $post->ID, '_reference', true );
echo "<pre>";
var_dump($reference_data);
echo "</pre>";
foreach ( $reference_data as $key => $value ) {
echo "<pre>";
echo $key . " => " . $value . "<br />";
echo "</pre>";
}
$reference_data["reference_page_lead"];
$reference_data["reference_page_url"];