WordPress get posts by category
function Last5posts() {
$args = array( 'posts_per_page' => 5, 'category_name' => 'uncategorized');
$last_5_posts_query = new WP_Query( $args );
while($last_5_posts_query->have_posts()) :
$last_5_posts_query->the_post();
$link = get_permalink();
$title = get_the_title();
$date = get_the_date();
$content .= '<div class="latest-posts">';
$content .= '<h3><a href='.$link.' target="_top">'.$title.' / '.$date. '</a></h3>';
$content .= '<p class="excerpt">' .get_the_excerpt(). '</p>';
$content .= '</div>';
endwhile;
return $content;
}
add_shortcode('Last5Posts', 'Last5posts' );