Support

Account

Home Forums General Issues Include customized excerpt filter with ACF Post Object field Reply To: Include customized excerpt filter with ACF Post Object field

  • The hook for get_the_excerpt passes 3 arguments.

    
    apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
    

    You need a different filter for each of these hooks.

    The first line of your filters will need to be different based on the hook

    
    $post_id = ( $post ) ? $post->ID : get_the_ID();
    

    for the “get_the_excerpt” filter you need to look at the 3rd argument $post->ID

    This part does not matter in this case because you are not using the function the_excerpt() in this case, but it is something to be aware of. Your filter would not work at all if you used that function in your loop because you are basing it on the global $post value. In your loop over the posts of the post object field you are not altering the global $post and this means that you’re using the wrong post ID in your code. The function the_excerpt() only works on the global $post object.