Support

Account

Home Forums Backend Issues (wp-admin) PDF url is when saving '' and when updating it is filled in Reply To: PDF url is when saving '' and when updating it is filled in

  • You are trying to get the value of the field before ACF has saved that value. You need to run a function after ACF is done saving so that there is a value to get. You do this by using acf/save_post https://www.advancedcustomfields.com/resources/acf-save_post/

    
    function save_mytype($post_id) {
      if (get_post_type($post_id) == 'mytype' ){
        $file = get_field('pdf', $post_id);
        $url = $file['url'];
        $post = array(
          'ID' => $post_id
        );
        if ($url != '') {
          $post['post_content'] = '[flipbook pdf"'.$url.'" theme="light"]';
          //createNewsItem($post);
        }else{
          $post['post_content'] = 'Something is wrong';
        }
        // remove filter to avoid infinite loop
        remove_filter('acf/save_post', 'save_mytype');
        wp_update_post($post);
        add_action('acf/save_post', 'save_mytype');
      }
    }
    add_action('acf/save_post', 'save_mytype');