Support

Account

Home Forums ACF PRO problem with custom_field_excerpt

Solving

problem with custom_field_excerpt

  • 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

    http://screenshot.net/x4komsm

  • 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!

  • This reply has been marked as private.
  • 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.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.