There are several issues in your code. Like, syntax error in line 4. Undefined $out variable PHP notice. And main issue is that you are not using the loop properly. In foreach, you need to use setup_postdata()
and it also needs to be reset properly. Please check following.
add_shortcode( 'custom-home-posts', function ( $atts ) {
extract(shortcode_atts(array(
"num" => '5',
"cat" => '',
), $atts));
global $post;
$out="";
$myposts = get_posts('numberposts=".$num."&order=DESC&orderby=post_date&category='.$cat);
$i = 0;
foreach($myposts as $post){
setup_postdata( $post );
$i++;
if ($i == 1)
{
$out.='<div class="post">
<h3 class="post-title"><a href="'.get_the_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
<span class="author-date-blog">'.get_the_author().'|'.get_the_date('d M Y').'</span>
<div class="excerpt">
'.get_the_content().'
<div class="read-more">
<a href="'.get_the_permalink().'#disqus_thread">Leave a Comment >></a>
</div>
</div>
</div>';
}
else
{
$out.='<div class="post">
<div class="thumb">
<a href="'.get_the_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail('blog-thumb').'</a>
</div>
<h3 class="post-title"><a href="'.get_the_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
<span class="author-date-blog">'.get_the_author(). '|'.get_the_date('d M Y').'</span>
<div class="excerpt">'
.get_the_excerpt().
'<div class="read-more">
<a href="'.get_the_permalink().'">Read More >></a>
</div>
</div>
</div>';
}
wp_reset_postdata();
}
return html_entity_decode($out);
} );