Home › Forums › General Issues › Post featured image from category custom field image. › Reply To: Post featured image from category custom field image.
All of this would be much easier if the plugin you mention has a filter that will allow you do substitute the category image for the post’s featured image, and this is what I’d look at before doing all of the updating that would be required to do it that way. I have never used this plugin, so, I cannot say if it’s possible to do or not. You should contact the plugin author and ask.
To do this the hard way.
Set 1:
Create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/
In this filter check the category of the post, if it is in the category you want then get the post ID of the image save in the category and update the featured image value for the post.
Getting values from terms is covered on this page https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Setting the featured image on a post is covered here https://support.advancedcustomfields.com/forums/topic/set-featured-image-from-acf-image-field/
Step 2:
What happens when someone updates the image on the category?
In this case you need an acf/save_post filter that will run when the category is updated. Let’s say that your photo category has an ID of 100. The your filter would check to see if the post ID that ACF passes is “term_100” and if it is then you need to get the image ID value, do a query to get all of the posts that are in that category and update the value of featured image value of every post.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.