2

This is a mixitup plugin filtering. I wanted to use only two categories to filter the posts. *Update, I fixed the filtering menu but still can't display the posts by those two categories.

My categories are "Events" (id=3), and "News" (id=4).

Update

I got it work partly in the filtering menu by using 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
            }
        } 
    ?>

But I can't get it to display posts by those two categories

<?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">
Kristina Bressler
  • 1,642
  • 1
  • 25
  • 60

1 Answers1

1

Finally, figured it out! It's all in the wp_query. All I need to add is

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

and I'm able to display the posts by those two categories...

Kristina Bressler
  • 1,642
  • 1
  • 25
  • 60