Skip to content

Instantly share code, notes, and snippets.

@MWDelaney
Created January 9, 2018 15:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MWDelaney/fd0bed89b891e3ff0850428703786397 to your computer and use it in GitHub Desktop.
Save MWDelaney/fd0bed89b891e3ff0850428703786397 to your computer and use it in GitHub Desktop.
<?php
/**
* Set excerpt from ACF field
*/
add_action('acf/save_post', function($post_id) {
$post_excerpt = get_field( 'short_description', $post_id );
if ( ( !empty( $post_id ) ) AND ( $post_excerpt ) ) {
// Update post options array
$update_post_excerpt_args = array(
'ID' => $post_id,
'post_excerpt' => $post_excerpt,
);
wp_update_post( $update_post_excerpt_args );
}
}, 50);
@cotasson
Copy link

Thank you, this has been quite useful to me !
And I shared it here : https://wordpress.stackexchange.com/questions/124422/mandatory-excerpt-for-custom-post-type

@NJN04
Copy link

NJN04 commented Jun 13, 2023

Git perfect!
Solved 3 days of failed attempts.
Big thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment