Related posts only for certain categories

Hi there,
I have a related posts function that appears after the content on any post.
I want to add four related posts to the bottom of posts that are in any of three specific categories.

    function x_child_init(){
    	add_shortcode( 'x_recent_posts_related', 'x_recent_posts_related' );
    }

    add_filter( 'the_content', 'add_related_posts_shortcode' );
    function add_related_posts_shortcode($content){
  if ( is_singular('post') && in_category( array( 1,31,32 ) )) {
        $content .= '<p></p>';
        $content .= do_shortcode('[x_recent_posts_related count="4"]');
      }
      return $content;
    }

Hi There,

I’ve just tested your code under my local installation and it’s working fine.

Could you please tell us which issue are you facing on this code?

Thanks.

Hi there, sorry for the confusion @thai. Please consider closed