2017-12-05 2 views
0

나는 모든 게시물을 날짜순으로 출력하고 있으며 사용자가 카테고리를 통해 정렬 할 수있는 몇 개의 버튼을 추가하려고합니다.자료 Wordpress 정렬을 기준으로

내가 가진 두 범주는 "이벤트"및 "뉴스"입니다. 사용자가 '일정'버튼을 클릭하고 이벤트 소식 이외의 모든 소식을 삭제할 수 있고 '뉴스'와 '전체'중 하나를 삭제할 수 있습니다.

플러그인을 통해 코드 솔루션을 찾고 있습니다. 건배.

답변

0
<div class="filter-dropdown"> 
     <?php $args = array('type' => 'CUSTOM_POST_TYPE','orderby' => 'name','order' => 'ASC','taxonomy' => 'TAXONOMY_NAME'); ?> 
     <?php $terms = get_terms(array('taxonomy' => 'TAXONOMY_NAME', 'parent' => 0)); 
     $allcats = array(); 
     ?> 
<!-- Nav Tabs --> 
    <ul class="nav nav-tabs" role="tablist"> 
       <li class="active" role="presentation"> 
       <a href="#tab1" aria-controls="tab1" role="tab" data-toggle="tab" aria-expanded="true">ALL</a> 
       </li> 
     <?php $i=1; 
     $class=''; 
      foreach ($terms as $category) { 
      if ($category->category_parent == 0 && $category->slug != 'all') { 
       $i++; 
       array_push($allcats,$category->slug); 
        echo '<li role="presentation" class=""><a href="#tab'.$i.'" aria-controls="tab'.$i.'" role="tab" data-toggle="tab">'.$category->name.'</a></li>'; 
      } 
      } 
     ?> 
    </ul> 
<!-- --> 
    </div> 

    <div class="tab-content"> 
     <?php $post_type = 'CUSTOM_POST_TYPE'; $taxonomy = 'TAXONOMY_NAME'; ?> 
<!-- Code to Display All Posts --> 
     <div id="tab1" class="tab-pane fade active in" role="tabpanel"> 
      <div class="row"> 
      <?php $args = array('post_type' => $post_type, 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $allcats, 'include_children' => false,),),); 
       $posts = new WP_Query($args); 
       $j = 0; 
       if($posts->have_posts()){ 
        while($posts->have_posts()) { 
        $posts->the_post(); 
         $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); ?> 
         <div class="col-sm-6 col-xs-6"> 
         <div class="tab_pic"> 
          <img src="<?php echo $image[0]; ?>" alt="" /> 
          <a href="<?php the_permalink(); ?>" class="tab_hover"> 
          <span class="inner_txt"><?php the_title(); ?></span> 
          </a> 
         </div> 
         </div> 
        <?php } 
       } 
      wp_reset_query(); ?> 
      </div> 
     </div> 
<!-- --> 
     <?php $i=1; $class=''; 
      foreach($allcats as $cats) { 
      $postcat= $category->cat_ID; $i++; ?> 
       <div role="tabpanel" class="tab-pane fade" id="tab<?php echo $i; ?>"> 
       <div class="row"> 
        <?php $args = array('post_type' => $post_type, 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => $taxonomy,'field' => 'slug', 'terms' => $cats, 'include_children' => false,))); 
        $posts = new WP_Query($args); if($posts->have_posts()){ while($posts->have_posts()) { $posts->the_post(); 
        $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); ?> 
         <div class="col-sm-6 col-xs-6"> 
         <div class="tab_pic"> 
          <img src="<?php echo $image[0]; ?>" alt="" /> 
          <a href="<?php the_permalink(); ?>" class="tab_hover"> 
          <span class="inner_txt"><?php the_title(); ?></span> 
          </a> 
         </div> 
         </div> 
        <?php } } wp_reset_query(); ?> 
       </div> 
       </div> 
       <?php } ?> 
      </div> 
+0

치명적인 오류가 반환되었습니다. '치명적인 오류 : 캐치 오류 : /home/produ325/public_html/eccdev/wp-includes/class-wp-query.php:3090의 배열로 WP_Query 유형의 객체를 사용할 수 없습니다. 스택 추적 : # 0' – Eivic