2017-12-08 8 views
0

カテゴリに基づいてカスタム投稿タイプを表示する必要があります。テストされた用語をリストアップし、それらが表示されるので、分類法が読み取られているだけで、表示するポストを取得できません。用語でカスタム投稿タイプを表示

  $terms = get_terms('team'); 

     $args = array(
      'posts_per_page' => 30, 
      'post_type' => 'team', 
      'taxonomy' => '$terms' 
       ); 

       $q = new WP_Query($args); 

        if ($q->have_posts()) { 
         while ($q->have_posts()) { 
         $q->the_post(); 

         if(has_term('link-to-bio')) { 

          // do stuff 
+0

のStackOverflowへようこそ!私たちがあなたのお手伝いをするために、あなたの質問を更新して、あなたの関連コードを[最小限で完全で検証可能な例](https://stackoverflow.com/help/mcve)に表示させてください。詳細については、[良い質問をする方法](https://stackoverflow.com/help/how-to-ask)に関するヘルプ記事を参照してください。ありがとう! – dferenc

答えて

0

これが完成しました。 https://developer.wordpress.org/reference/functions/get_the_terms/でお答えコードを一新:

$args = array(
      'posts_per_page' => 30, 
      'post_type' => 'team' 
       ); 

       $q = new WP_Query($args); 

        if ($q->have_posts()) { 
         while ($q->have_posts()) { 
         $q->the_post(); 

         $terms = get_the_terms(get_the_ID(), 'team'); 

         if ($terms && ! is_wp_error('link-to-bio')) { 

          // do stuff 
0

はこれを試してみてください:

$args = array(
     'posts_per_page' => 30, 
     'tax_query' => array(
     array(
       'taxonomy' => 'name of your taxonomy', 
       'terms' => 'category id' 
      ), 
     ), 
     'post_type'  => 'team', 
     'post_status'  => 'publish' 
     ); 
関連する問題