ID, $tax, array( 'fields' => 'ids' ) ); } // if no tags, then by cat or custom tax if ( empty( $tax_term_ids ) ) { // remove post_tag to leave only the category or custom tax if ( $tag_key !== false ) { unset( $taxs[ $tag_key ] ); $taxs = array_values($taxs); } $tax = $taxs[0]; $tax_term_ids = wp_get_object_terms( $post->ID, $tax, array('fields' => 'ids') ); } if ( $tax_term_ids ) { $args = array( 'post_type' => $post->post_type, 'posts_per_page' => $count, 'orderby' => 'rand', 'tax_query' => array( array( 'taxonomy' => $tax, 'field' => 'id', 'terms' => $tax_term_ids ) ), 'post__not_in' => array ($post->ID), ); $related = get_posts( $args ); if ( $related ) { ?>

More articles you might be interested in .....