2013-12-20 3 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] =>이 두 번째 제 [3] =>이 제 [2] => 이것은 여섯 [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>'; 
    } 
관련 문제