# Fill the Excerpt From an ACF Summary Field

> Copies an ACF summary field into the post excerpt on save when the excerpt is empty, so themes, feeds and search results show your summary.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: acf, excerpt, automation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/acf-excerpt-from-field/

## Code

```php
// Summary field and the post types it applies to.
$wpide_acf_excerpt_field = 'summary';
$wpide_acf_excerpt_types = array( 'post' );

add_action( 'acf/save_post', function ( $post_id ) use ( $wpide_acf_excerpt_field, $wpide_acf_excerpt_types ) {
    if ( ! is_numeric( $post_id ) || wp_is_post_revision( $post_id ) || ! in_array( get_post_type( $post_id ), $wpide_acf_excerpt_types, true ) || '' !== trim( (string) get_post_field( 'post_excerpt', $post_id ) ) ) {
        return;
    }

    $summary = sanitize_textarea_field( (string) get_post_meta( $post_id, $wpide_acf_excerpt_field, true ) );

    if ( '' !== $summary ) {
        wp_update_post( array( 'ID' => (int) $post_id, 'post_excerpt' => $summary ) );
    }
}, 20 );
```

## Notes

Set the field name and post types. Excerpts you write by hand are kept.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Fill the Excerpt From an ACF Summary Field" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
