2017-10-24 1 views
0

일부 분류와 post_types trough custom post type UI 플러그인을 만들었습니다. 페이지에 양식이있는 taxonomy_id를 전달하면 올바르게 수신됩니다. [var_dump($_POST)]는 번호 예제 30을 표시합니다. 해당 사용자 정의 게시물 유형 범주의 게시물을 표시하고 싶습니다. 아래 코드를 시도했지만 아무 것도 반환하지 않습니다.WP_Query cpt taxonomy가 게시물을로드하지 않습니다.

$args = [ 
    'tax_query' => array(
     array(
      'taxonomy' => 'school_type', 
      'field' => 'term_id', 
      'terms' => array('30','22'), 
      // 'operator' => 'IN' 
     ), 
    'post_type' => 'school', 
    ) 
]; 
if($q->have_posts()): 
    while($q->have_posts()){ 
     $q->the_post(); 
     echo the_title(); 
    } 
else: 
    echo 'nothing'; 
endif; 

아무도 도와 줄 수 있습니까?

답변

0

tax_query 배열에 post_type이 있고, 존재하지 않을 경우 $q을 타겟팅합니다 (어쨌든 볼 수는 없습니다). 이 같은

시도 뭔가 : -

$args = array(
    'post_type' => 'school', 
    'tax_query'  => array(
     array(
      'taxonomy'  => 'school_type', 
      'field'   => 'term_id', 
      'terms'   => array('30','22'), 
     ), 
    ), 
    'numberposts' => -1 
); 
$q = new WP_Query($args); 
if($q->have_posts()): 
    while($q->have_posts()){ 
     $q->the_post(); 
     echo the_title(); 
    } 
else: 
    echo 'nothing'; 
endif; 
0

당신은이 같은 $에 인수 변수가 다음 게시물을 얻을 수있는 WP_Query() 객체를 사용한다.

$args = array(
     'post_type' => 'school', 
     'posts_per_page'=>30, 
     'post_status' => 'publish', 
     'tax_query' => array(array(
      'taxonomy' => 'school_type', 
      'field' => 'term_id', 
      'terms' => array('30','22'), 
    ); 

    $q = new WP_Query($args); 
    if($q->have_posts()): 
      while($q->have_posts()){ 
       $q->the_post(); 
       echo the_title(); 
      } 
     else: 
      echo 'nothing'; 
     endif; 
0

이 경우 라인

0

변화 유형 및 업데이트 영구 링크를 게시하는 사용자의 고유 주소 전에 $q = new WP_Query($args);을 넣고,이 도움이되기를 바랍니다.

+0

어떻게 변경하나요? 이 코드를 사용자 정의 페이지 템플리트에 추가했습니다. –

+0

settings-> permalinks-> permalink를 이동하여 이름을 게시하고 permalink 구조를 업데이트하십시오. 그리고 $ q = new를 추가하십시오 WP_Query ($ args); 이 경우 전에 코드에서 조건. –

0

내 잘못해서 죄송합니다. 여기에 내가이 코드를 변경하고 아무것도 바뀌지 않았다.

$args = array(
    'post_type' => 'school', 
    'tax_query'  => array(
     array(
      'taxonomy'  => 'school_type', 
      'field'   => 'term_id', 
      'terms'   => array('30','22'), 
     ), 
    ), 
    'numberposts' => -1 
); 
$q = new WP_Query($args); 
if($q->have_posts()): 
    while($q->have_posts()){ 
     $q->the_post(); 
     echo the_title(); 
    } 
else: 
    echo 'nothing'; 
endif; 
관련 문제