I’m here to ask you for help, I created a custom field taxonomy to upload an image in my categories.
now I would like those images to become the featured image of the post belonging to the categories.
That is, that all the posts belonging to the Photo category have the same featured image inserted as a custom field in the photo category.
I searched for information about it but I can’t find a solution, if you can help me thank you.
In the post template you would get the category of the post and then get the image field from the category and display that instead of the post’s featured image. https://www.advancedcustomfields.com/resources/taxonomy/
Sorry for the late reply
What I need is that the image is actually assigned to the post.
So that the TheGrid Plugin uses that image as a preview.
TheGrid uses the featured image of the post to create a preview, what I need is that assigning a category to the post category assigns a featured image to the post.
In this way the user does not have to load the Featured image manually, in order to simplify the work.
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.
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/
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.
You must be logged in to reply to this topic.
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!
© 2019 Advanced Custom Fields. Subscribe