• I am trying to run the following function only on a custom post type called ‘properties’. The function replaces the title of the post with the address from an ACF google maps field. Currently, the function works on the custom post. However, it deletes the title from all other posts. Thus, I want to limit the functionality of this function to just the CPT ‘properties’.
    I have tried the functions ‘get_post_type’ and ‘is_singular’ as conditional statements. Neither work. Using the two above conditions fixes all other post types (nav, normal posts), but breaks the functionality of the CPT.

    Here is the function:

    function prop_title( $post_id) {
    
    				$title = get_field('address');
    				$data = implode (',',$title);
    				$new_slug = sanitize_title( $data );
    
    				$my_post = array(
    				'ID'           => $post_id,
    				'post_title' => $data,
    				'post_name' => $new_slug,
    				);
    				wp_update_post( $my_post );
    				return $data;
    
    	}
    add_action('the_title', 'prop_title', 1,1);
  • The topic ‘Perform Function Only on Custom Post Type’ is closed to new replies.