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