ID, 'amazing-portfolio-category' ); //Pluck out the IDs to get an array of IDS $term_ids = wp_list_pluck($terms,'term_id'); //Query posts with tax_query. Choose in 'IN' if want to query posts with any of the terms //Chose 'AND' if you want to query for posts with all terms $second_query = new WP_Query( array( 'post_type' => 'amazing-portfolio', 'tax_query' => array( array( 'taxonomy' => 'amazing-portfolio-category', 'field' => 'id', 'terms' => $term_ids, 'operator'=> 'AND' //Or 'AND' or 'NOT IN' )), 'posts_per_page' => 3, 'ignore_sticky_posts' => 1, 'orderby' => 'rand', 'post__not_in'=>array($post->ID) ) ); if($second_query->have_posts()) : ?>

Related Projects: