Как использовать только две категории в WordPress get_terms

Это фильтрация плагинов mixitup. Я хотел использовать только две категории для фильтрации сообщений. * Обновление, я исправил меню фильтрации, но все еще не могу отображать сообщения по этим двум категориям.

Мои категории: "События" (id=3) и "Новости" (id=4).

Обновить

Я получил его работать частично в меню фильтрации с помощью включения

<?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">

1 ответ

Наконец-то разобрался! Это все в wp_query. Все, что мне нужно добавить, это

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

и я могу отображать сообщения по этим двум категориям...

Другие вопросы по тегам