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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.