Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Konrad Pilch
Konrad Pilch
2,435 Points

Function not Working

Why does this not work?

// Excerpts
function custom_field_excerpt($title) {
            global $post;
            $text = get_field($title);
            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);
        }
 <p><?php echo custom_field_excerpt('resource_post_content'); ?></p>

I'm using custome post types.

I'm sure this should work. And i cheched million times my name field.

Joel Bardsley
Joel Bardsley
31,249 Points

Try including the post ID parameter in the get_field() function, ie:

$text = get_field($title, $post->ID);
Konrad Pilch
Konrad Pilch
2,435 Points

It was actually working but i was checking different file lol

But thanks!

btw i checked the code out of curiosity, and it did work as well, i guess i'll live it like that.