2014-07-15 3 views
0

맞춤식 분류를위한 데이터가있는 json 파일이 있습니다. 그리고 필터를해야합니다. 포스트 메타 링크와 다른 필드에 아무런 문제가 없습니다. 하지만 나는 카테고리를 json으로 가져올 수 없습니다. 그런 다음 필터링 할 수 없습니다.사용자 정의 게시물 가져 오기

나는 대답이 매우 간단해야하지만 나는 2 일 동안 그것을 이해할 수 없다는 것을 알고있다.

function getItems($meta_query) { 

$params = array(
    'post_type'   => 'property', 
    'nopaging'   => true, 
    'post_status'  => 'publish', 
    'meta_query'  => array(), 

$meta_query = array('meta_query'=>array(), 'relation' => 'AND');  

if (!empty($_POST['city'])) 
{ 
    $params['meta_query'][] =array(
      'key' => 'property_city', 
      'value' => $_POST['city'], 
      'compare' => 'LIKE' 
     ); 
} 

if(!empty($_POST['parish'])) 
{ 
    $params['meta_query'][] = array(
      'key' => 'property_state', 
      'value' => $_POST['parish'], 
      'compare' => 'LIKE' 
    ); 
} 
//..................ETC.......................... 

내가 지금 범주에 대해 무엇을 가지고 :

//if (!empty($_POST['category'])) 
    /*{ 
    $params['meta_query'][] = array(
       'taxonomy' => 'pcategory', 
       'field' => 'slug', 
       'terms' => $_POST['category']->slug 
       ); 
    }*/ 

    $itemsQuery = new WP_Query(); 
    $properties = $itemsQuery -> query($params);  

    // add property details 
    foreach ($properties as $key => $property) { 
     // options 
     $property->optionsDir = get_post_meta($property->ID, 'property', true); 
     $city = get_post_meta($property->ID, 'property_city', true); 
     $parish = get_post_meta($property->ID, 'property_state', true);  
     $link = get_permalink($property->ID); 
     $category = get_the_terms($property->ID,'pcategory'); 


     $properties[$key]->link = array(
     'link' => $link, 
     ); 

     //postmeta 
     $properties[$key]->postmeta = array(
     'city' => $city, 
     'parish' => $parish, 
     'region' => $region, 
     'link' => $link, 
     'category' => $category, 
     ); 

    } 

    return $properties; 
} 

답변

0
$category = get_the_terms($property->ID,'pcategory'); 

코드가 반환됩니다보다도 배열 개체로 용어 ID, 이름, 용어에 대한 슬러그 정보, 등의 모든 세부 사항, .

필요한 세부 정보를 추출해야합니다.

또한 "pcategory"는 사용자 지정 분류입니다. 이 사용자 정의 분류이며, 워드 프레스 분류 기본하지

따라서,

$properties[$key]->postmeta = array(
     'city' => $city, 
     'parish' => $parish, 
     'region' => $region, 
     'link' => $link, 
     'category' => $category, 
     ); 

'카테고리', 아래의 코드에서 제대로 해석되지 않습니다. 이러한 매개 변수는 WP_Query()로 전송하는 경우에는 아래와 같이 'tax_query'을 언급 할 수

, 여기

'tax_query' => array(
     array(
      'taxonomy' => 'pcategory', 
      'field' => 'slug', 
      'terms' => 'demo' 
     ) 

은 "데모"사용자 정의 분류 예를 들어 슬러그이다.

단일 게시물에도 여러 카테고리가 연결될 수 있습니다. 따라서 원하는 카테고리 세부 정보를 추출해야합니다.

'tax_query'에서 'term_id'또는 기타 세부 정보를 지정할 수도 있습니다.

+0

고마워 .. 나는 그랬다. 내가 뭘 잘못했는지는 모르겠지만 파이어 버그의 콘솔은 json 카테고리 배열에 [ "잘못된 분류법"]을 쓰려고 멈추지 않습니다. – user3727355

관련 문제