You advised me to this code:
If you are looking to create a post excerpt, I would recommend you make use of the following function in your functions.php file:
function custom_field_excerpt() {
global $post;
$value = get_field(‘field_name’);
if ( ” != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters(‘the_content’, $text);
$text = str_replace(‘]]>’, ‘]]>’, $text);
$excerpt_length = 20; // 20 words
$excerpt_more = apply_filters(‘excerpt_more’, ‘ ‘ . ‘[…]’);
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters(‘the_excerpt’, $text);
}
You can then replace this line $value = get_field(‘field_name’) with your custom field call and then on your template use the following code echo custom_field_excerpt();
BUT IT DOES NOT WORK:
http://screenshot.net/dgm23hv.jpg
Hi @inforesist
I’m not sure which thread you are referring to, but could you please try this code?
function custom_field_excerpt() {
global $post;
$text = get_field('wysiwyg_test', $post->ID);
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 20; // 20 words
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
Hope this helps.
Hi @inforesist
Could you please share the JSON export file of your field group and your PHP file where the code is located?
Thanks!
Hi @inforesist
I’m afraid the line at fault is not the code I gave you before. I’m sorry I can’t help you with it.
Thanks.
The topic ‘problem with custom_field_excerpt’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.