true, 'ignore_sticky_posts' => true, 'posts_per_page' => 3, ); $current_object = get_queried_object(); if ( $current_object instanceof WP_Post ) { $current_id = $current_object->ID; if ( absint( $current_id ) > 0 ) { // Exclude current post. $cosme_related_posts_args['post__not_in'] = array( absint( $current_id ) ); // Include current posts categories. $categories = wp_get_post_categories( $current_id ); if ( ! empty( $categories ) ) { $cosme_related_posts_args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $categories, 'operator' => 'IN', ) ); } } } $cosme_related_posts_query = new WP_Query( $cosme_related_posts_args ); if( $cosme_related_posts_query->have_posts() ): ?>