2013-12-20 47 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>'; 
    } 
相关问题