WordPress – Custom plugin to return related posts by category

Solution:1

Categories are pulled as expected. But in argument in WP_Query, you got one problem. It should be category__in, NOT category_in.

Try this:

'category__in'    => $categoriesIds,

See documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Solution:2

Use following code

<?php

$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
 <ul> 
        <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            <?php the_content('Read the rest of this entry &raquo;'); ?>
        </li>
    </ul>   
<?php }
wp_reset_postdata(); ?>

It will display related post from the same category with the post excerpt and title , however if want this code to display just the title of related post then remove this line,

<?php the_content('Read the rest of this entry &raquo;'); ?>