List posts from same category

This goes inside the loop on single.php – This lists all the posts in the same category as the current post.

/**
 * Snippet Name: List posts from same category
 * Snippet URL: https://www.wpcustoms.net/snippets/list-posts-from-same-category/
 */
  cat_ID;
$args=array(
'cat' => $cat,
'order' => DESC,
'orderby' => rand,
'post__not_in' => array($post->ID,56),
'posts_per_page' => 55,
'caller_get_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '

'. $category->cat_name . '

'; while ($my_query->have_posts()) : $my_query->the_post(); ?>

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x