Skip to content

Instantly share code, notes, and snippets.

@santanup789
Created February 22, 2022 14:09
Show Gist options
  • Save santanup789/629e7981230d59383b36b2a2d90f3d16 to your computer and use it in GitHub Desktop.
Save santanup789/629e7981230d59383b36b2a2d90f3d16 to your computer and use it in GitHub Desktop.
Display the published date 2days prior when publishing the post on the front end to show the 2days prior date
<!-- We will not do anything to change the detfault publishe date -->
<!-- We will use the publishe date to create a date 2days prior of the publishe date using a custom date time field. -->
<!-- Create a date-time custom field using ACF plugin for your CPT or any kind of post type -->
<!-- Use this function in your theme's functions.php and use the custom field's meta name to fire the update query -->
<!-- Also you can change the prior day or post day by just changing "-1 day or +1 day" inside this function -->
<?php
add_action( 'acf/save_post', 'my_acf_save_post' );
function my_acf_save_post( $post_id ) {
//$date = get_the_date( 'Y-m-d H:i:s', $post_id );
$date = date('j-F-Y', strtotime('-2 day', get_the_date('U', $post_id)));
update_field( 'post_meta_name', $date, $post_id );
}
?>
<!-- Change the return format of the date and time field to get the desired result for the front end from the date time custom field -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment