Support

Account

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();
    
    }