[Resolved] Add ACF custom fields to a post excerpt

Home Forums Support [Resolved] Add ACF custom fields to a post excerpt

Home Forums Support Add ACF custom fields to a post excerpt

Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #1944966
    Elvin
    Staff
    Customer Support

    Try this:

    add_filter( 'the_excerpt', function( $excerpt ) {
        $the_custom_field = get_field('year', get_queried_object_id());
        // return the excerpt followed by the_custom_field value
        return $excerpt . $the_custom_field; 
    } );
    #1944971
    Tyler

    No luck but I sincerely thank you for trying. I have a support ticket sent to ACF to see if they have any insight. I’ve also tried a number of similar code snippets found through searches but I can’t get anything to change.

    Just to be clear, I’m expecting the Excerpt field at the bottom of the post editor to be populated with the year field. I have another plugin that will only use the Excerpt field to display data alongside the post title. Maybe what’s happening is the data is being passed somewhere that I can’t see?

    #1944987
    Elvin
    Staff
    Customer Support

    I’m not fully sure where year ACF is associated to so get_queried_object_id() is pretty much a guess. My assumption was, it was a field assigned to a taxonomy term, to be displayed on the current taxonomy archive.

    I’d change get_queried_object_id() to get_the_ID() or just omit the ID if the ACF is assigned to post.

Viewing 3 posts - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.