Created
October 15, 2014 01:45
-
-
Save tatemz/a104cf3d93bbaa43ffac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ), | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are ACF field ID's such as
field_543aee78c4176
constant, or does ACF ever change that internal reference?