Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Created February 27, 2015 22:33
Show Gist options
  • Save raphaelchaib/a1f04712a20a8b6837f3 to your computer and use it in GitHub Desktop.
Save raphaelchaib/a1f04712a20a8b6837f3 to your computer and use it in GitHub Desktop.
WordPress: Fix quick update with custom fields changing post_title or other fields
<?php
add_action( 'save_post', 'elo_people_custom_permalink' );
// add_filter( 'wp_insert_post_data', 'elo_people_custom_permalink' );
function elo_people_custom_permalink( $data, $postarr ) {
$post = get_post($data);
$exec_in = array('equipe', 'comunicador');
if( in_array($post->post_type, $exec_in) ) {
$post_title = get_post_meta($post->ID, '_people_nome', true);
$post_name = sanitize_title( $post_title );
remove_action( 'save_post', 'elo_people_custom_permalink' );
wp_update_post(array(
'ID' => $post->ID,
'post_title' => $post_title,
'post_name' => $post_name
));
add_action( 'save_post', 'elo_people_custom_permalink' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment