Skip to content

Instantly share code, notes, and snippets.

@KimBranzell
Last active May 22, 2016 22:42
Show Gist options
  • Save KimBranzell/2c327a4790a62abb35d14d0705d96389 to your computer and use it in GitHub Desktop.
Save KimBranzell/2c327a4790a62abb35d14d0705d96389 to your computer and use it in GitHub Desktop.
Updates the parent CPT's (in a hierarchical CPT mode) last modified time to that of it's last modified child.
<?php
add_action( 'save_post','changeLastModified' );
function changeLastModified( $post ){
if ( 'YOUR_CUSTOM_POST_TYPES_NAME' == get_post_type( $post ) ) {
if( ! ( wp_is_post_revision( $post ) ) ) {
$sync_time = array();
$sync_time['ID'] = wp_get_post_parent_id( $post );
$sync_time['post_modified'] = get_post_field( 'post_modified', $post, 'raw' );
remove_action( 'save_post', 'changeLastModified' );
wp_update_post( $sync_time, true );
add_action('save_post', 'changeLastModified' );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment