Support

Account

Forum Replies Created

  • Ok, I swapped $my_post for $post as advised and now the content is copied over but in 2-3 instances. It’s like if the loop happens multiple times before settling.

    The code looks like this now:

    <?php
    global $post;
    $args = array( 
    	'post_type' => 'post', 
    	'posts_per_page' => -1,
    	'post_status' => 'any'
    );
    
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post );
    
    	$custom_field_raw = get_the_content().get_field('chapter_1');
    	$custom_field_text_only = wp_strip_all_tags($custom_field_raw);
    
    	$post = array(
    		'ID'           => get_the_ID(),
    		'post_content' => $custom_field_raw
    	);
    
    	wp_update_post( $post );
    
    endforeach; 
    wp_reset_postdata();

    Ideally I’d need to move all chapters at once and make sure the loop doesn’t create multiple instances of every field. Could you help, please?

    THANK YOU!

    EDIT:
    I’m using this to add PHP to the page: https://wordpress.org/plugins/insert-php-code-snippet/

  • Hello There,

    Apologies for resuming this post.

    I’m trying to do exactly this but the code above changes only the latest post before spitting an error message.

    I have 5 ACF, which splits long posts in 5 chapters (chapter_1, chapter_2 and so on).
    I’d like to move away from it and move the content of all posts from the ACFs to the_content and given I’m an absolute nob I can’t seem to be able to do it.

    Could anyone help me through the process, please?

Viewing 2 posts - 1 through 2 (of 2 total)