2015-02-23 66 views
0

我在自定義帖子類型的wordpress中有以下多維數組。自定義後類型名稱是:「引用wordpress自定義帖子類型元字段值

我怎樣才能得到以下值:reference_page_leadreference_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

感謝,我決定:

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

數據是序列化的,所以你需要反序列化它。

Reference to unserialize

$result = unserialize($theArray["_reference"][0]); 

echo $result['reference_page_url']; 
echo $result['reference_page_lead']; 
+0

感謝,但它的工作不是:( – wpdaniel 2015-02-23 14:07:03

+0

只注意到_reference是一個數組,更新上面的例子^^ – beije 2015-02-23 14:19:20

相關問題