ID; $related_posts_text = applica_get_option('related_posts_text'); $no_of_related_posts = absint(applica_get_option('no_of_related_posts')); $order = esc_attr(applica_get_option('related_posts_order')); $orderby = esc_attr(applica_get_option('related_posts_orderby')); // Covert id to ID to make it work with query if ('id' == $orderby) { $orderby = 'ID'; } $category_ids = array(); $categories = get_the_category($post_id); if (!empty($categories)): foreach ($categories as $cat): $category_ids[] = $cat->term_id; endforeach; endif; if (!empty($category_ids)): $related_posts_args = array( 'category__in' => $category_ids, 'post_type' => 'post', 'post__not_in' => array($post_id), 'posts_per_page' => $no_of_related_posts, 'ignore_sticky_posts' => 1, 'orderby' => $orderby, 'order' => $order, ); $related_posts_query = new WP_Query($related_posts_args); if ($related_posts_query->have_posts()): ?>

have_posts()): $related_posts_query->the_post(); ?>