Skip to content

Instantly share code, notes, and snippets.

@tatemz
Created October 15, 2014 01:45
Show Gist options
  • Save tatemz/a104cf3d93bbaa43ffac to your computer and use it in GitHub Desktop.
Save tatemz/a104cf3d93bbaa43ffac to your computer and use it in GitHub Desktop.
<?php
if ( empty( $_POST['acf'] ) ) {
return;
}
if (
!isset( $_POST['acf']['field_543aee78c4176'] )
|| !isset( $_POST['acf']['field_543aee84c4177'] ) )
{
return;
}
$timestamp_from = strtotime( $_POST['acf']['field_543aee78c4176'] );
$timestamp_to = strtotime( $_POST['acf']['field_543aee84c4177'] );
$uncertain_date = ( intval( $_POST['acf']['field_543dcf05b7eb1'] ) == 1 );
$format = ( $uncertain_date ) ? 'F Y' : 'F j, Y';
$from = date( $format, $timestamp_from );
$to = date( $format, $timestamp_to );
$y1 = date( 'Y', $timestamp_from );
$y2 = date( 'Y', $timestamp_to );
$dates = array( $from, $to );
if ( $y1 == $y2 && !$uncertain_date ) {
$from = date( 'F j', $timestamp_from );
} else if ( $y1 == $y2 && $uncertain_date ) {
$from = date( 'F', $timestamp_from );
$m1 = date( 'F', $timestamp_from );
$m2 = date( 'F', $timestamp_to );
$dates = ( $m1 == $m2 ) ? array( $to ) : $dates;
}
wp_update_post( array(
'ID' => $post_id,
'post_title' => implode( ' - ', $dates ),
) );
@nathansh
Copy link

Are ACF field ID's such as field_543aee78c4176 constant, or does ACF ever change that internal reference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment