Skip to content

Instantly share code, notes, and snippets.

@micjamking
Created June 21, 2016 21:32
Show Gist options
  • Save micjamking/44802905b0cf55d03b36f8c6df5d445a to your computer and use it in GitHub Desktop.
Save micjamking/44802905b0cf55d03b36f8c6df5d445a to your computer and use it in GitHub Desktop.
[WordPress Plugin] Copy ACF field to Post Excerpt
<?php
/**
* Plugin Name: ACF Field to Excerpt
* Plugin URI: http://wordpress.stackexchange.com/q/70990/12615
*/
function acf_to_excerpt(){
$post_type = 'post';
$field = 'summary';
$args = array(
'post_type' => $post_type,
'numberposts' => -1
);
$posts = get_posts( $args );
foreach ( $posts as $post ){
if ( $post->post_excerpt === '' ) {
$content = get_field( $field, $post->ID, false );
if ( $content !== '' ) {
$updated_post = [];
$updated_post = get_post( $post->ID, 'ARRAY_A' );
$updated_post['post_excerpt'] = $content;
wp_update_post($updated_post);
}
}
}
}
register_activation_hook( __FILE__, 'acf_to_excerpt' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment