Support

Account

Home Forums General Issues Post featured image from category custom field image.

Solving

Post featured image from category custom field image.

    • Salias

    • March 15, 2019 at 2:40 am

    Hello everyone,

    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/

    • Salias

    • March 22, 2019 at 3:18 am

    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.

    Many tanks

  • 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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.