Home › Forums › General Issues › acf/update_value & wp_update_post to copy WYSIWYG to the_content() in template? › Reply To: acf/update_value & wp_update_post to copy WYSIWYG to the_content() in template?
Alright, I’m documenting this in case anyone in the future needs it. Took extra care to put the right search terms in the thread title, etc.
Here’s what I got working. Don’t use acf/update_value
. You want to use ‘acf/save_post’.
Next, in functions.php, for some reason using `if( if_page_template(”) )’ was not working at all. It was causing the field to be deleted.
But you had to “qualify” it in some way to make sure you’re only running on the right custom post template. So what I did was a check to see if the field I’m copying from exists, and it ONLY exists on that custom post template. So that check works out.
Here’s the code:
// Take the first WYSIWYG ACF field and copy it into the_content() in order to populate the_excerpt()
function my_acf_copy_content( $post_id ) {
if ( get_field('acf_site_text_box_top') ) {
$value = get_field('acf_site_text_box_top');
wp_update_post( array( 'ID' => $post_id, 'post_content' => $value ) );
return $value;
}
}
add_filter('acf/save_post', 'my_acf_copy_content', 20);
Be careful because without the qualifier, it flat out deletes your entire post on any post not using that custom field, which you then have to retrieve from the revisions.
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.