Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active April 6, 2022 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishterk/2258f3f19a99acd3da4024f4130741c0 to your computer and use it in GitHub Desktop.
Save mishterk/2258f3f19a99acd3da4024f4130741c0 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'get_the_excerpt', function ( $excerpt, $post ) {
if ( ! empty( $excerpt ) ) {
return $excerpt;
}
// On a specific post type, use an ACF field value as the excerpt.
if ( $post->post_type === 'my_custom_post_type' ) {
$excerpt = get_field( 'product_description', $post->ID );
}
return $excerpt;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment