2017-01-18 1 views
0

나는 관련 Wordpress 사용자 정의 게시물 및 범주를 쿼리하려고합니다. (. 모든 categorie 이름이 표시 될 때까지 반복 유지) : Wordpress custom query displayWordpress 질의 범주 이름 및 관련 게시물

내 쿼리 코드 :

<div id="page-content-wrapper"> 
    <div class="container-fluid"> 
     <div class="lookbook-header"> 
      <div class="wrap"> 
       <p class="text-left">lookbook</p> 
      </div> 
     </div> 

     <?php 
     $taxonomy = 'lookbook_categories'; 
$terms = get_terms($taxonomy); 

    $args=array(
    'taxonomy' => 'lookbook_categories' 
    'post_type' => 'lookbook', 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'caller_get_posts'=> 1 
    ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 
     if ($terms && !is_wp_error($terms)) : 
     foreach ($terms as $term) { ?> 
      <div class="lookbook-category"> 
       <p class="text-center"> 
        <?php echo $term->name; ?> 
       </p> 
      </div> 
      <?php 
if($my_query->have_posts()) { 
     echo ''; 
     $count=0; 
while ($my_query->have_posts()) : $my_query->the_post(); 
if($count == 3) {?> 
       <div class="row"> 
        <?php } 
    ?> 
         <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 no-padding"> 
          <div class="lookbook-item"> 
           <div class="hvrbox"> 
            <?php 
            $image = get_field('lookbook_image'); 
            if(!empty($image)): ?> <img src="<?php echo $image['url']; ?>" alt="news" class="img-responsive" /> 
             <?php endif; ?> 
              <div class="hvrbox-layer_top"> 
               <div class="hvrbox-text"> 
                <div class="separator"></div> 
                <h3><?php the_title();?></h3> 
                <div class="separator"></div> 
                <p> 
                 <?php the_field('excerpt');?> 
                </p> 
               </div> 
              </div> 

           </div> 

          </div> 
         </div> 
         <?php  
    $count++; 
     if($count == 3) echo '</div>'; 
     endwhile; 
} 
             } 
        endif; 
wp_reset_query(); 
?> 

       </div> 
    </div> 
질의, 이상하게 역할을 해당 범주

예제 이미지도 관련되지 카테고리 이름과 모든 관습 게시물 표시

나는 카테고리 이름 + 카테고리 (안해서 또 다시 모든 게시물)

답변

0

하는 당신은 get_terms 리터에 배열 전달하려는 관련 게시물을 표시 할 것 이케 :

$terms = get_terms(array(
    'taxonomy' => 'lookbook_categories', 
    'hide_empty' => false, 
)); 

당신이 여기에 대한 자세한 내용을보실 수 있습니다 : 이미 에코 $ term-> 이름 $ 용어의 이름을 검색하고 https://developer.wordpress.org/reference/functions/get_terms/

+0

을; 내가 얻고있는 유일한 문제는 전화 customposts의 dublicated 배열입니다 (관련되지 않거나 표시된 카테고리와 관련 없음) @nate –

관련 문제