2013-12-20 74 views
0

我在這裏有一個情況,我得到的數組自定義字段不正確。我可以知道如何讓所有自定義字段順序嗎?按照順序在wordpress上顯示自定義字段

,我用它來獲取自定義陣列功能是:

$title = get_post_meta($post_id, "cap-display_name", false); 
foreach($title as $a){ 
    echo 'hello '.$a.'<br><br>'; 
} 

但是,我得到的輸出是:

hello this is first 

hello this is second 

hello this is third 

hello this is six 

hello this is four 

hello this is five 

hello this is seven 

假想的輸出是:

hello this is first 

hello this is second 

hello this is third 

hello this is four 

hello this is five 

hello this is six 

hello this is seven 

我可以知道如何獲得上述輸出嗎?

的print_r($標題)將得到這樣的:

陣列([0] =>這是第一個[1] =>這是第二[2] =>這是第三[3] =>這是六[4] =>這是四[5] =>這是五[6] =>這是七)

+0

顯示數組的結構'print_r($ title)'' – Dinesh

回答

0

我認爲你需要爲此運行你的自定義SQL。例如:

global $wpdb; // your DB object 
    $sql = "SELECT m.meta_value FROM wp_postmeta m where m.meta_key = 'cap-display_name' and m.post_id = {$post_id} order by m.meta_id"; 
    $results = $wpdb->get_results($sql); 
    foreach($results as $result) 
    { 
     echo 'hello '.$result->meta_value.'<br><br>'; 
    } 
相關問題