Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong post date shown (wordpress)

So, on a first.php, I have <?php echo get_the_date('',$post->id); ?> to show the post date which, for example, shows "2 days ago."

Using the ajax, I am getting the post_id of the post via $_REQUEST['next_post'] then parsing it onto second.php

For the same post, I am using <?php echo get_the_date('',$_REQUEST['next_post']); ?> to get the date.

But the date simply shows as "46 years ago."

I am not sure why the date for the same post is different. Actually any posts loaded via ajax shows 46 years ago as the post publish date.

Does anyone know how to fix this?

Thanks!

like image 923
Steve Kim Avatar asked Feb 01 '26 07:02

Steve Kim


1 Answers

$_REQUEST['next_post'] is probably empty. get_the_date uses unix time stamps that count seconds since 1970-01-01 00:00:00. Since you are posting null or 0 to get_the_date it will correctly display 46 years ago. Make sure $_REQUEST['next_post'] is set in the request header. You can use the chrome web tools to check if it is. Press ctrl + shift + j and select the network tab. There you can see your requests with all request data.

like image 78
Pablo Jomer Avatar answered Feb 02 '26 20:02

Pablo Jomer