Home › Forums › ACF PRO › Populate acf field with post content › Reply To: Populate acf field with post content
First step, you’re in a function so you need to declare the global $post.
If that does not work the add the post id to the function calls instead of letting WP try to figure them out. I’d probably do this anyway.
add_action( 'init', 'copy_data' );
function copy_data() {
if ( !is_admin() )
return;
// declare global, you cant access $post without it
global $post;
// WP_Query arguments
$args = array (
'post_type' => array( 'ze_event' ),
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
update_field( 'field_56b4d48d4b471', get_the_content($post->ID), $post->ID );
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
}
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.