-
-
Save groupewibi/a598c001f9b6fa8945df54bf6394dc32 to your computer and use it in GitHub Desktop.
[WordPress Plugin] Copy ACF field to Post Excerpt
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 | |
/** | |
* 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