2017-12-05 19 views
0

私はすべての投稿を日付順に出力しており、ユーザーがカテゴリを使って並べ替えることができるいくつかのボタンを追加したいと思います。ワードプレス並べ替えポストカテゴリ別

「イベント」と「ニュース」の2つのカテゴリがあります。ユーザーが「イベント」ボタンをクリックし、イベント投稿以外のすべての投稿を「ニュース」と「すべて」の両方に表示させることができます

プラグインでコードソリューションを探しています。乾杯。

答えて

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

関連する問題