0

I am getting only one post .when I two post assigned in one category . Please let me know how to get all post of a category.

<?php foreach ( $terms as $term ) { ?>
    <!--<div id="<?php //echo $term_id = $term->term_id;?>" class="tabcontent"><!-->
          <?php //echo $term_id = $term->term_id;?>
    <?php
                             //loop the names of the slugs for the portfolio_categories
    $terms = get_terms( array ( 'taxonomy' => 'portfolio_categories', 'hide_empty' => false, 'parent' => 0, 'orderby' => 'date', 'order' => 'DESC' ));
    foreach ($terms as $term) {
      $slug= $term->slug;
      $term_id = $term->term_id;
    $args = array(                          
                                            'post_type' => 'Portfolio',
                                            'portfolio_categories' =>$slug,  
                                            'orderby' => 'ID',
                                            'order' => 'DESC',
                                            'hide_empty' => 1,
                                            'posts_per_page' => 6
                                        );

                                        $posts_query = new WP_Query( $args );
                                    if (have_posts()) :    
                                  while (   $posts_query->have_posts() ) : $posts_query->the_post();
    //echo '<div id="'.$term_id .'" class="tabcontent1">';
                                  ?>
    <div id="<?php echo $term_id = $term->term_id;?>" class="tabcontent">
       <?php echo '<div class="col-1-3">';?>
        <!--<div class="col-1-3"><!-->
       <?php echo $term_id = $term->term_id;?>     
       <?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );?>
       <div id="<?php //echo $term_id = $term->term_id;?>" class="wrap-col" >
                        <div class="item-container">
                            <a class="fancybox" href="<?php echo $thumbnail[0]; ?>" data-fancybox-group= gallery>   
                          <div class="overlay text-center">
                            <div class="overlay-inner">
                              <h4>BAKER CANISTER PUMP</h4>
                            </div>
                          </div><img src="<?php echo $thumbnail[0];?>"></a> </div>
                      </div>
           <!-- </div><!-->
     <?php echo '</div>';//echo '</div>';?>
     </div>
        <?php
    endwhile;endif;  wp_reset_postdata();
    }

after var_dump( $posts_query); enter image description here

1
$args = array(                          
'post_type' => 'Portfolio',
'tax_query' => array(
    array(
        'taxonomy' => 'portfolio_categories',
        'terms' => $slug,
        'field' => 'slug',
    )
),
'orderby' => 'ID',
'order' => 'DESC',
'posts_per_page' => -1
);
  • 1
    lukgoh@removed but no luck – sanjay kumar Oct 4 '17 at 19:38
  • ukgoh@you there? bro – sanjay kumar Oct 4 '17 at 19:49
  • Updated my answer – lukgoh Oct 4 '17 at 19:52
  • lukgoh@thanks bro but it's not working gonna die right now . I have no idea how to solve this ,please help me – sanjay kumar Oct 4 '17 at 19:57
  • Haha, don't stress mate lets work this out. You should check to see if it is pulling the correct data. Use var_dump($slug); to see what that is returning. Then use var_dump($posts_query); to see if that has more than one result... – lukgoh Oct 4 '17 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.