wordpress自定义帖子类型元字段值

时间:2015-02-23 13:29:39

标签: php wordpress

我在自定义帖子类型的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"
  }

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

数据已序列化,因此您需要对其进行反序列化。

Reference to unserialize

$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"];