【问题标题】:How to use only two categories in get_terms wordpress如何在 get_terms wordpress 中只使用两个类别
【发布时间】:2016-02-23 02:06:53
【问题描述】:

这是一个mixitup插件过滤。我只想使用两个类别来过滤帖子。 *更新,我修复了过滤菜单,但仍然无法显示这两个类别的帖子。

我的类别是“事件”(id=3)和“新闻”(id=4)。

更新

我通过使用 include 在过滤菜单中部分工作

<?php 
        $terms = get_terms('category', 'include=6,7&hide_empty=0'); // get all categories, but you can use any taxonomy
        $count = count($terms); //How many are they?
        if ( $count > 0 ){  //If there are more than 0 terms
            foreach ( $terms as $term ) {  //for each term:
                echo "<li class=".filter." data-filter='.".$term->slug."'>" . $term->name . "</li>\n";
                //create a list item with the current term slug for sorting, and name for label
            }
        } 
    ?>

但我无法让它显示这两个类别的帖子

<?php 
$args = array (
    'post_type'              => array( 'posts' ),
    'order'                  => 'ASC',
);

 $the_query = new WP_Query( $args ); //Check the WP_Query docs to see how you can limit which posts to display ?>
<?php if ( $the_query->have_posts() ) : ?>
    <div id="isotope-list">
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 
    $termsArray = get_the_terms( $post->ID, 'events');  //Get the terms for this particular item
    $termsString = ""; //initialize the string that will contain the terms
        foreach ( $termsArray as $term ) { // for each term 
            $termsString .= $term->slug.' '; //create a string that has all the slugs 
        }
    ?> 
    <div class="<?php echo $termsString; ?> item mix">

【问题讨论】:

    标签: php wordpress mixitup


    【解决方案1】:

    终于明白了!这一切都在 wp_query 中。我需要补充的是

    $the_query = new WP_Query( 'cat=6,7');

    我可以按这两个类别显示帖子...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 2016-10-07
      相关资源
      最近更新 更多