Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save raphaelchaib/91e5fdea00322d626545 to your computer and use it in GitHub Desktop.

Select an option

Save raphaelchaib/91e5fdea00322d626545 to your computer and use it in GitHub Desktop.
WordPress: Create custom permalink based on custom field or other value.
<?php
add_filter( 'wp_insert_post_data', 'cg_custom_insert_post_data' );
function cg_custom_insert_post_data( $data ) {
//You can make some checks here before modify the post data.
//For example, limit the changes to revista post type
if( 'revista' == $data['post_type'] ) {
$edicao_num = 'Edição: '.$_POST['_edicao_num'];
$data['post_name'] = sanitize_title( $edicao_num );
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment