0

I would like my site to show the x time ago on posts but we also have lots of events listed that are effected by the sitewide change and are also showing x time ago dates too even if they are in the future.

We have ACF pro installed on our site and we have created a custom date field for each post that we can print onto the frontpage underneath each post they are related to.

Is there a way to manipulate the field to show x time ago as opposed to just showing the time and date?

Thanks

0

Editing the theme is a good way to get this done, if it's a theme with updates from someone else I would make a child theme to prevent your changes being overwritten: https://developer.wordpress.org/themes/advanced-topics/child-themes/

Another option is to make a plugin that utilizes a shortcode that allows any Wordpress editor to just plug that shortcode into the Wordpress page editor. There might be a plugin that already does this, search?

Wherever you need the date changed you could add this code in replacement:

<?php
$acfCustomDate = strtotime(get_field('custom_date'));
$currentDate = strtotime(getdate());

$secsAgo = $currentDate - $acfCustomDate;// == strtotime gives seconds
$daysAgo = $secsAgo / 86400;

if($daysAgo > 0)
    echo "Posted $daysAgo days ago";
else
    echo "Posted $daysAgo days in the future!";
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.