2017-02-22 14 views
0

array_column을 사용하여 wp_get_post_terms에서 term_ids 배열을 추출하려고하는데 아무 것도 반환하지 않습니다.Wordpress array_column이 wp_get_post_terms에서 작동하지 않습니다.

$atype: Array 
(
    [0] => WP_Term Object 
    (
     [term_id] => 51 
     [name] => Office 
     [slug] => office 
     [term_group] => 0 
     [term_taxonomy_id] => 51 
     [taxonomy] => property_category 
     [description] => 
     [parent] => 0 
     [count] => 1 
     [filter] => raw 
    ) 

) 
$types: Array 
(
) 
$types2: Array 
(
    [0] => 51 
) 

왜 작동 array_column되지 않습니다

여기
$atype = wp_get_post_terms($property_ID, 'property_category', true); 
$types = array_column($atype, 'term_id'); // Not working so using array map 
$types2 = array_map(function($te) { 
    return $te->term_id; 
}, $atype); 

echo '$atype: '; 
echo '<pre>'; print_r($atype); echo '</pre>'; 
echo '$types: '; 
echo '<pre>'; print_r($types); echo '</pre>'; 
echo '$types2: '; 
echo '<pre>'; print_r($types2); echo '</pre>'; 

이 결과 : 여기

코드인가? 문서를 기반으로해야합니다. 나는> php 5.5를 사용하고있다. 야 http://php.net/manual/en/function.array-column.php

답변

1

객체 S 아닌 2 차원 어레이의 wp_get_post_terms 창 어레이 때문이다. array_column은 PHP 7.0.0 이전의 2 차원 배열에서만 작동합니다.