Display category and correct date of WordPress posts

I’ve had trouble getting the correct date of each post to display. It is displaying the date of the first entry even though I have used ‘new WP_Query’.

I also can’t get the category type to display.

$blogloop = new WP_Query( array( 'numberposts' => '3' ) );
    $recent_posts = wp_get_recent_posts( $blogloop );
$categories = get_categories( array(
'orderby' => 'name',
 'order'   => 'ASC'
) );
foreach( $recent_posts as $recent ){
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
     echo ' <div class="col-md-4 col-xs-12">
     <a href="' . get_permalink($recent["ID"]) . '"><div class="blog-item"><div class="home-blog-img" style="background-image: url('.get_the_post_thumbnail_url($recent["ID"]).')"></div><div class="home-blog-content"><h3>'. $recent["post_title"] .'</h3><p>'. get_the_date('D M j',$recent) .'</p><span> | </span><p>'. sprintf( esc_html__( 'Category: %s', 'textdomain' ), $category_link ) .'</p></div></div></a></div> ';
<?php wp_reset_query();?>

Read more here: Display category and correct date of WordPress posts

Leave a Reply

Your email address will not be published. Required fields are marked *