If you use the save_post
hook, every time content is published or updated, the featured image will be refreshed. Note: make sure ACF is set to return an image ID, which is not its default.
add_action( 'save_post', 'wpse_set_featured_image' );
function wpse_set_featured_image($post_id) {
// get author id
$author_id = get_the_author_id($post_id);
// get author's image
$author_image_id = get_user_meta($author_id, 'your_acf_img_var_name', true);
// fallback image
if(empty($author_image_id)) {
// set to an existing image ID to use as a fallback
$author_image_id = '4';
}
// at last, set the post featured image
set_post_thumbnail($post_id, $author_image_id);
}
Related Posts:
- WordPress Internal @ Mentions
- How can I add an Author filter to the Media Library?
- Add ‘if exists’ to filter
- How to link current user to their author page through shortcodes
- How Does comment_author Filter Work?
- How to removes all instances of thumbnails displayed in my theme?
- Override has_post_thumbnail function
- Use of comment_reply_link_args filter
- Remove Comment Author Link only for subscribers
- Removing URL and adding container around image in the featured image metabox
- How to apply filter on get_the_post_thumbnail()
- Distinguish between page and post in function
- WordPress set featured image to first image of the post
- Print url to default featured image
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- changing size image within the content
- can’t output gray scaled image I’ve created using add_image_size
- Wrapping Featured Image on Add/Edit Page in div?
- add_filter with specific thumb names
- what is __return_false in filters
- Passing Additional Parameters to add_filter Callable
- Custom theme hooks / filters – passing arguments
- Change upload directory on custom plugin page
- What params are available with the_content filter?
- How to hook wp_list_pages?
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- apply_filters(‘the_content’, $content) alternative
- How to use the_excerpt in a filter hook?
- Changing document title only on a custom page template
- Shortcodes not resolved in AJAX call response
- Filter the blog’s title without using global variables
- user_has_cap filter allows edit but will not allow save
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
- How do I pass the value from a foreach loop to an add_filter function? [closed]
- Search results sorted by post types
- Add guid filter to attachment in media library grid mode
- Pass parameter to the upload_dir filter
- Filter or Hook to catch pre-rendering of post content
- check to see if hook is available
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- Use add_filter on concatenated string variable
- Filter users by custom colum not meta key
- How to allow users to view pending posts of a specific custom post type?
- Remove filter callback: method in class
- How can I exclude tags from category_rss function?
- How to filter meta_values using REST API
- How do I use remove_action on an add_action that uses an array?
- Admin Backend – Search Pages only by title
- Change the default 10-day expiration for the password protected pages cookie
- Add content as soon starts
- Access get_the_title() from ‘excerpt_length’ filter
- Wrong post_status notice after wp_insert_post_data
- Comment search plugin
- How can I replace an oEmbed URL in post with actual embed HTML
- How do you get specific tags from the_content?
- Add a filter inside an action init
- How to display the content HTML of a page without displaying the gallery code as well
- Is it possible to apply_filter on a wp_ajax_ action?
- Apply filters with multiple filters
- Using add_filter to prepend content, result is out of order
- Prevent reset password specific user role
- get_posts() interrupt because of filter
- WooCommerce coupon hook argument NULL when using filter woocommerce_get_shop_coupon_data
- How can I edit comment meta value before it is saved?
- Why current_user_can(‘edit_comment’) always true?
- Disable sanitize_file_name on upload without modifying functions.php
- Redirect after post deleted
- How to stop filter from running on the index.php page?
- Filter Shortcodes when using get_page
- Usage of filters
- Where exactly does the edit_{taxonomy} hook fire?
- Filter Media by attached page or blog post in Library
- How to stop DOMDocument destroying embeds?
- How to modify image caption in posts?
- Extend Nonce Lifetime for Specific Nonce Creation
- Run `wp_insert_post_data` on all posts
- How can I pass instance via apply_filters as a parameter?
- Consult array data in REST API Filter
- WordPress add_filter to post_date
- Add filter return false not working
- create a shortcode with acf including a filter
- Custom permalink for attachment
- Overriding Generated Attachment Post URL
- Pagination while keeping the filters
- Apply a filter str_replace on specific caracters array in the_content()
- get_the_archive_title hook unwanted changes!
- Change add_filter based on Ajax
- Best way to add image to recent posts widget?
- How to check which submission button was clicked?
- check, if any “add_action” function contains string XXXXXXXXX
- How to add more than one custom metadata as filter on the post list page?
- remove_action conditionally for Custom Post Type – not working
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- 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?
- Assign new post author IF another user in custom field on post transition
- Filter and manipulate the get_current_user() function
- add_filter(‘the_content’, ‘method’) does not trigger my custom method