Support

Account

Feature image from first gallery image

I know this has been covered before, but I am having an unexpected problem. I want the featured image to take the first image of the gallery – it does this with the code below, but only after I Update the post within Admin – the featured post is not set when the post is initially published…Any ideas?

"save_post_{$post_type}" runs before "save_post". ACF does not set the values of the field until the second hook. So you are trying to get values from a field that has not been set yet. When you update the post the second time (and after) you are using values that were saved the previous time the the post was saved and it will not reflect changes correctly if the first image in the gallery has been changed.

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.