Advanced Custom Fields
Move the content of a custom field to the_content(); automatically (4 posts)

  1. Animalejourbano
    Posted 1 year ago #

    Is there any way to move automatically the content of a custom field to the_content(); wp field?
    I need to make this change in a website with more than 400 articles, and is too hard to make it manually. Is there any easy way?

    Thanks a lot!!!


  2. Fumito MIZUNO
    Posted 1 year ago #

    One way is using a filter. You can use the_content filter to modify the content.

    function add_my_custom_field($data) {
        // _FIELD_NAME_HERE_ should be replaced with the custom field name.
        $data .= esc_html( get_field('_FIELD_NAME_HERE_'));
        return $data;

    Paste this code to your theme's functions.php.

  3. Animalejourbano
    Posted 1 year ago #

    Thanks a lot for your help! Let's see if it works.

  4. spudlogic2
    Posted 7 months ago #

    Hey Animalejourbano,
    I'm trying to do this with the repeater field.

    I'm pulling in post_content from several page to make a tabbed section but one page is made up of a ACF repeater field.

    This is what I have that's pulling in the content

    	$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'asc' ) );
    	foreach( $mypages as $page ) {
    		$content = $page->post_content;
    		if ( ! $content ) // Check for empty page
    		$content = apply_filters( 'the_content', $content );
    		<div class="<?php echo $page->post_name; ?>">
    			<h2><?php echo $page->post_title; ?></h2>
    			<?php echo $content; ?>
    <?php } ?>

    and then I have this in it's own template

    <?php if( have_rows('blood_components') ): ?>
    	<?php while( have_rows('blood_components') ): the_row();
    		// vars
    		$image = get_sub_field('image');
    		$content = get_sub_field('text');
    		<div class="bc">
    			<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    				<?php echo $content; ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    I think it should be some mod to the filter but I'm not quite sure how that works.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic