Blog Post On Home Page Displaying Page Published Date Not Post Published Date

That’s expected, this code gets the date of the current post:

$post_date = get_the_time( 'd-m-y', $post->ID );

But you’re not inside the post loop yet, so the current post is the page you’re on. the_post is what sets the current post, so you need to call this inside the loop, not outside.

There are some other issues:

  • Use an editor that auto-indents code, especially if you’re sharing it, indentation avoids an entire group of bugs
  • echo esc_url( get_the_permalink( $post_id ) ); refers to $post_id which is never defined, it’s just pulled out of thin air
  • There is no else case, if no posts are found it’ll just be blank