Last active
May 22, 2016 22:42
-
-
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.
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 | |
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