Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created August 15, 2012 21:52
Show Gist options
  • Save micahwave/3364024 to your computer and use it in GitHub Desktop.
Save micahwave/3364024 to your computer and use it in GitHub Desktop.
guest author latest post
/**
* Add the most recent post id to each guest author as meta
*/
function time_guest_author_latest_post( $post_id, $post ) {
if( $post->post_type == 'post' ) {
$guest_id = get_post_meta( $post_id, 'time_guest_author', true );
if( $guest_id ) {
// get the guests most recent post id
$latest_post_id = get_post_meta( $guest_id, 'time_latest_post_id', true );
if( ( $latest_post_id && $post_id > $latest_post_id ) || !$latest_post_id ) {
update_post_meta( $guest_id, 'time_latest_post_id', $post_id );
}
}
}
}
add_action( 'save_post', 'time_guest_author_latest_post', 97, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment