2016-05-10 6 views
0

私は何も表示しない私のWP_Queryに問題があります。 私はカスタムフィールドの値で選択する1つのカスタム投稿タイプのみを返すカスタムクエリを設定しようとしています。Wordpress Wp_queryカスタムフィールド表示なし

カスタムフィールドにはACFを使用します。ここで

は私が持っているコードです:

<section class="ui very relaxed list custom"> 
<?php while(have_posts()) : the_post(); ?> 
    <article> 
     <header class="page-header expo"> 
      Some content with custom field 
     </header> 
     <section class="content"> 
      <?php 
      $artiste_name = get_field('relation_artiste'); 
      /*$name = $artiste['post_name']; 
      // vars 
      $field_name = "relation_artiste"; 
      $field = get_field_object($field_name); 

      echo $field['post_name'] . ': ' . $field['value']; 
      */ 

      //$field_name = "relation_artiste"; 
      $args = array(
      'post_type' => 'Artiste', 
      'meta_key' => 'relation_artiste', 
      'meta_value' => $artiste_name 
      ); 
      // query 
      $the_query = new WP_Query($args); 
      ?> 
      <?php //echo $artiste_name ?> 
      <?php if($the_query->have_posts()): ?> 
       <?php while($the_query->have_posts()) : $the_query->the_post(); ?> 
        <aside class="item"> 
         <section class="ui small images"> 
          <?php the_post_thumbnail('portrait', array('class'=>"home img-size")); ?> 
         </section> 
         <p class="item-description"> 
          <?php the_excerpt(2); ?> 
         </p> 
         <footer class="item-foot"> 
          <a class="nextlink right floated content" href="<?php the_permalink(); ?>">Voir l'artiste <i class="material-icons">keyboard_arrow_right</i></a> 
         </footer> 
        </aside><!-- Aside info --> 
       <?php endwhile; ?> 
        <?php endif; ?> 
      <?php wp_reset_query(); ?> 

       <?php the_content(); ?> 

      </section> 
     </article> 
<?php endwhile; ?> 

答えて

0

あなたは下のリンクをチェックしてください。このためにWP METAクエリを使用する必要が

https://codex.wordpress.org/Class_Reference/WP_Meta_Query

+0

あなたの答えヒマンシュに感謝、しかし、私は本当に理解していない..私は '$ the_query = new WP_Query($ args);によって' $ the_query = new WP_Meta_Query($ args); 'を変更する必要がありますか? – Adam

+0

$引数=配列( \t \t \t \t \t \t \t \t \t \t 'post_type' => '芸人' \t \t \t \t \t \t \t \t \t \t \t 'meta_query' =>配列( \t \t \t \t \t \t \t \t \t \t \t \t 'meta_key' => 'relation_artiste'、 \t \t \t \t \t \t \t \t \t \t \t \t 'meta_value' => $ artiste_name \t \t \t \t \t \t \t \t \t \t \t) \t \t \t \t \t \t \t \t \t); \t \t \t \t \t \t \t \t \t //クエリ \t \t \t \t \t \t \t \t \t $ the_query =新しいWP_Query($ argsを);.私はこれを行うが、今は彼が私のカスタムフィールド「Artiste」を表示し、カスタムフィールドでは選択しなかった – Adam

関連する問題