Support

Account

Home Forums Front-end Issues Using acf field to define a new post content & title Reply To: Using acf field to define a new post content & title

  • Hi
    I use this code but at end of the title it add array.
    Any help would be greatly appreciated.

    
    add_action('acf/save_post', 'my_save_acfpost', 20);
    function my_save_acfpost($post_id){
      
      // Get the title from a field
      $karbar_title = get_field('field_5c6c298e83e41', $post_id);
      $hotel_title = get_field('field_5c6c298e83e40', $post_id);
      $tour_title = get_field('field_5c607a4750d32', $post_id);
      $tamas_title = get_field('field_5e0b69b807458', $post_id);
      
      $acfnew_title = $karbar_title . ' ' . $hotel_title . ' '. $tamas_title . ' ' . $tour_title;
      
      
      // Get the content from a field
      $tamas_content = get_field('field_5e0b6b410745b', $post_id);
      $hotel_content = get_field('field_5c6c376283e46', $post_id);
      $tour_content = get_field('field_5c59be78fa3e0', $post_id);
      
      $acfnew_content = $tamas_content . ' ' . $hotel_content . ' '. $tour_content ;
    	
      // Set the post data
      $newacf_post = array(
     
          'ID'           => $post_id,
          'post_title'   => $acfnew_title,
    	  'post_content'	=> $acfnew_content,
      );  
      // Update the post
      wp_update_post( $newacf_post );    
    }
    
    

    null