Support

Account

Home Forums Feature Requests Set 'Post Title' from two ACF fields value – Permalink Update Problem

Helping

Set 'Post Title' from two ACF fields value – Permalink Update Problem

  • Hi,

    i wanna set the post title from the value of two acf fields and I do it like the following (function great):

      add_action( 'pre_get_posts', 'js_search_filter' );
    
      function my_post_title_updater( $post_id ) {
    
    	if ( get_post_type() == 'video' ) {
    
    		$my_post = array();
    		$my_post['post_title'] = get_field( 'interpret_video', $post_id ) . ': ' . substr(get_field( 'titel_video', $post_id ), 0, 30) . '';
    		
    		// Update the post into the database
    		wp_update_post( $my_post );
    
    	}
    
    }
     
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_post_title_updater', 20);

    But now I wanna update the permalink of the now generatet title. How I gotta do this ?

  • 
    function my_post_title_updater( $post_id ) {
    
      if ( get_post_type() == 'video' ) {
    
        $my_post = array();
        $post_title = get_field('interpret_video', $post_id).': '. substr(get_field('titel_video', $post_id ), 0, 30);
        $post_name = sanitize_title($post_title);
        $my_post['post_title'] = $post_title;
        $my_post['post_name'] = $post_name;
        
        // Update the post into the database
        wp_update_post( $my_post );
    
      }
    
    }
     
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_post_title_updater', 20);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.