Last active
September 3, 2019 17:26
-
-
Save donini/7b1d481b37ee078addea042c9bdbf6da to your computer and use it in GitHub Desktop.
Override/extend post save
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', 'update_post_title' ); | |
function update_post_title( $post_id ){ | |
global $wpdb; | |
$post_type = get_post_type( $post_id ); | |
$title = ''; | |
if ( $post_type === 'store' ) { | |
$name = get_post_meta( $post_id, 'name', true ); | |
$title = $name; | |
} | |
if ($post_type === 'register') { | |
$first_name = get_post_meta( $post_id, 'first_name', true ); | |
$vat . = get_post_meta( $post_id, 'vat', true ); | |
$title = '##' . $first_name . '## ' . $vat; | |
} | |
if( $title !== '' ){ | |
$post = get_post( $post_id ); | |
$post->post_title = $title; | |
$post->post_name = sanitize_title( $title ); | |
remove_action( 'save_post', 'update_post_title' ); | |
wp_update_post( $post ); | |
add_action( 'save_post', 'update_post_title' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment