Last active
December 30, 2020 14:48
-
-
Save AaronRutley/c0a49d89daf92ad75b6a6112f6722f38 to your computer and use it in GitHub Desktop.
Save ACF Testimonials to post content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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