Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Last active December 30, 2020 14:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronRutley/c0a49d89daf92ad75b6a6112f6722f38 to your computer and use it in GitHub Desktop.
Save AaronRutley/c0a49d89daf92ad75b6a6112f6722f38 to your computer and use it in GitHub Desktop.
Save ACF Testimonials to post content
<?php // Save ACF Testimonials to post content
function ar_save_testimonials_to_content( $post_id ) {
// Only run this code if we're on a particilar post / page
if( $post_id === 1234 ) {
// Start an output buffer
ob_start();
// Loop over our testimonials
if ( have_rows( 'client_testimonials' ) ) : ?>
<ul class="testimonial-list">
<?php while ( have_rows( 'client_testimonials' ) ) : the_row(); ?>
<li class="testimonial-list__item">
<blockquote><?php the_sub_field( 'quote' ); ?></blockquote>
<cite><strong><?php the_sub_field( 'client_name' ); ?></strong> - <?php the_sub_field( 'business_name' ); ?></cite>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
// Store output buffer
$new_post_content = ob_get_clean();
// Update the post_content
wp_update_post( array('ID' => $post_id, 'post_content' => $new_post_content ));
}
}
// On ACF Save Post, Save our Testimoinals to post content
add_action('acf/save_post', 'ar_save_testimonials_to_content', 20); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment