In spite of what the Codex says, since WP 4.5, where the addition of the post argument to the function get_the_excerpt was added, this filter takes two arguments. The second argument is the post object whose excerpt you are manipulating.
So the function still works in the loop without an explicit post, we make the second argument optional.
add_filter( 'get_the_excerpt', 'wpse_242462_excerpt_filter' );
function wpse_242462_excerpt_filter( $excerpt, $post = null ){
if ( $post ) {
$ID = $post->ID;
} else {
$ID = get_the_ID();
}
$excerpt = get_post_meta( $ID, 'wpse_242462_meta_field', true);
return $excerpt;
});
Hopefully it goes without saying that you need to substitute whatever meta key you are already using.
Related Posts:
- Get excerpt from $post->post_content
- How to use the_excerpt in a filter hook?
- add_filter on “the_excerpt” only works when post does not have excerpt
- End excerpt at the end of the sentence
- get_the_excerpt() with fallback like the_excerpt()
- Buddypress: Edit activity when new blog post [closed]
- Why in archive page doesn´t show read more button with excerpt?
- the_excerpt filter with an empty excerpt
- Access get_the_title() from ‘excerpt_length’ filter
- Give “Read More” precedence over excerpt() word count
- How do I override the_excerpt so that it will display full content?
- the_excerpt filter doesn’t work as expected
- Excerpt is being added above the content, but it should be after it
- run shortcode in excerpt of single custom post type
- apply_filters(‘get_the_content’, $content) + Except
- Trimming a custom field to a length
- Adding html banner to posts
- Apply wordpress filter checking category
- Add Filter – Pass Variable (PHP < 5.3)
- Filter Post Title without affecting screen-reader-text
- Create different flavours of excerpt
- Cutting off excerpt with first sentence
- Auto-generated excerpt with shortcode and read more button/text link
- Read More in the actual excerpt
- is_page_template() doesn’t work with excerpt_length filter
- the_excerpt() does not work with has_excerpt()?
- get_the_excerpt on mobile still displays continue reading
- Custom excerpt_more filter not working when tag is present
- Why does using excerpt_more filter change link location?
- what is __return_false in filters
- Passing Additional Parameters to add_filter Callable
- How can I add an Author filter to the Media Library?
- Custom theme hooks / filters – passing arguments
- Change upload directory on custom plugin page
- How to hook wp_list_pages?
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- apply_filters(‘the_content’, $content) alternative
- Add wrapper to only youtube videos via embed_oembed_html filter function
- Changing document title only on a custom page template
- Shortcodes not resolved in AJAX call response
- Possible to filter the posts or categories that XML-RPC users see in their mobile application?
- wp_link_pages output appears twice
- Multiple Ajax Data Action
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- How do I pass the value from a foreach loop to an add_filter function? [closed]
- Change WordPress RSS link with filter?
- How do I replace a render_callback function for a block?
- check if FILTER(“the_content”) is being executed in `the_post()`
- Change Password Strength Indicator names?
- Can the wp_filter object hold multiple values with the same key
- Limit RSS feed to previous calendar month
- How to stop wrapping comments in P tag
- How to modify core when there is no hook?
- Is this the proper way of switching the “Edit My Profile” link with my BuddyPress “Extended Profile” link?
- html tags in gettext hook get escaped
- How to remove action with slashes and arrows?
- Set default terms for new posts / CPTs
- Get .subsubsub count of post per status queried using pre_get_posts
- Better extend a class or use add filter/action hooks?
- Adaptive product filters for WooCommerce
- Adding a Clone link to product attributes – post_row_actions() filter, or how to override a Class question
- wp_upload_bits Upload Specific Sizes Only
- Plugin options, presets and filters : can you help me improve my workflow?
- Why does adding a filter to ‘the_title’ break the server?
- Wrapping my head around add_filter
- How to add_filter to an OOP based apply_filter(‘foo::bar’, $a);
- Help with filter for wp_notify_moderator()
- Change custom post type GUID in RSS
- Conflict calling an add_filter() twice
- How would I be able to use a font awesome icon as a user’s avatar?
- Add something after a filter
- add_filter the_content doesn’t work
- Redirect to woocommerce checkout after adding to cart – item already in cart
- Add filter unless it is being called under specific function
- Filter / add_action to upgrade.php page
- How do I add a line break to a string that is output by PHP?
- style_loader_tag not changing stylesheet to preload
- add_filter doesn’t return false?
- Distinguish between page and post in function
- Display posts from today and future in Elementor ‘posts widget’
- Right filter for rewriting page statuscode
- Changing title using filter not working with argument
- Archive Widget – Count only parent posts
- adding an action inside if condition not working
- Change URLs in default WordPress slider to relative from absolute
- Print url to default featured image
- Change add_filter based on Ajax
- What action/filter can be used for modifying the page to be rendered?
- Adding user filter – Not updating data in URL
- check, if any “add_action” function contains string XXXXXXXXX
- How to add more than one custom metadata as filter on the post list page?
- Add Default WordPress Formatting To Data From External SQL Tables?
- Joining tables not working in the post editor page
- Auto append text after the title?
- filter a list by gender
- add_filter(‘the_content’, ‘method’) does not trigger my custom method
- Better way to change the default password reset url with the woocommerce one?
- woocommerce_coupon_is_valid_for_product not working to exclude specific product tag
- Replacing text using add_filter
- Background color and background image below element in Contact Form 7 – error tip [closed]