每个类别只有一个帖子

时间:2017-10-04 作者:sanjay kumar

我只得到一个职位。当我在一个类别中分配两个职位时。请让我知道如何获得一个类别的所有职位。

<?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();
    }
aftervar\\u dump($posts\\u query);enter image description here

1 个回复
最合适的回答,由SO网友:lukgoh 整理而成
$args = array(                          
\'post_type\' => \'Portfolio\',
\'tax_query\' => array(
    array(
        \'taxonomy\' => \'portfolio_categories\',
        \'terms\' => $slug,
        \'field\' => \'slug\',
    )
),
\'orderby\' => \'ID\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1
);
结束

相关推荐

Virtual Pages plugins

我很难让插件正常工作Virtual Pages (WordPress插件可简化虚拟页面的创建)我确实进行了编辑,根据查询创建了一个循环。add_action( \'gm_virtual_pages\', function( $controller ) { /* Creating virtuals pages for companies */ $args = array( \'post_type\' => array(\'companies\',), \'post_status\'