Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f07f1f0

Browse files
Create use-acf-field-as-fallback-for-excerpt.txt
https://gist.github.com/mishterk/2258f3f19a99acd3da4024f4130741c0
1 parent ae9c87c commit f07f1f0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_filter( 'get_the_excerpt', function ( $excerpt, $post ) {
2+
if ( ! empty( $excerpt ) ) {
3+
return $excerpt;
4+
}
5+
6+
// On a specific post type, use an ACF field value as the excerpt.
7+
if ( $post->post_type === 'my_custom_post_type' ) {
8+
$excerpt = get_field( 'product_description', $post->ID );
9+
}
10+
11+
return $excerpt;
12+
}, 10, 2 );

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /