Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function biwp_contributor_name($post_id) {
- $corporate = get_field('biwp_corporate', $post_id ); //get Corporate checkbox value
- if ($corporate) { //if Corporate is checked, use biwp_cname (Corportate Name)
- $name = get_field('biwp_cname', $post_id );
- } else { //if Corporate is unchecked, use biwp_gnames (Given Names) and biwp_snames (Surnames)
- $gnames = get_field('biwp_gnames', $post_id );
- $snames = get_field('biwp_snames', $post_id );
- $name = $gnames .' '. $snames;
- }
- return $name;
- }
- add_filter('acf/update_value', 'biwp_fix_contributor_title', 10, 3);
- function biwp_fix_contributor_title( $value, $post_id, $field ) {
- if (get_post_type($post_id) == 'contributor') {
- $name = biwp_contributor_name($post_id);
- $new_title = $name;
- $new_slug = sanitize_title( $new_title );
- // update post
- $biwp_contributor = array(
- 'ID' => $post_id,
- 'post_title' => $new_title,
- 'post_name' => $new_slug,
- );
- if ( ! wp_is_post_revision( $post_id ) ){
- // unhook this function so it doesn't loop infinitely
- remove_action('save_post', 'biwp_fix_contributor_title');
- // update the post, which calls save_post again
- wp_update_post( $biwp_contributor );
- // re-hook this function
- add_action('save_post', 'biwp_fix_contributor_title');
- }
- }
- return $value;
- }
- add_action('save_post', 'biwp_fix_contributor_title', 12);
- function biwp_fix_contributor_title ($post_id) {
- if ( $post_id == null || empty($_POST) )
- return;
- if ( !isset( $_POST['post_type'] ) || $_POST['post_type']!='contributor' )
- return;
- if ( wp_is_post_revision( $post_id ) )
- $post_id = wp_is_post_revision( $post_id );
- global $post;
- if ( empty( $post ) )
- $post = get_post($post_id);
- if ($_POST['biwp_corporate']!='') {
- global $wpdb;
- $name = biwp_contributor_name($post_id);
- $where = array( 'ID' => $post_id );
- $wpdb->update( $wpdb->posts, array( 'post_title' => $name ), $where );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement