Home Forums General Issues Get the ID of an image field set to return the URL


Get the ID of an image field set to return the URL

  • I have an ACF Image type field, for which I have set the Return format to Image URL.

    The problem is that at some place, the ID would be more useful than the URL. I can’t easily change the setting to return an array instead of the URL, as that will affect all other places in my code (many files) where I’m simply pulling the Image as the URL…

    So, is there any built in function to automatically get the ID of an Image field that’s set to normally return the URL?

  • WOW John!!! I had never noticed that 3rd parameter. Indeed that was exactly what I wanted! If only I had your answer yesterday, I wouldn’t have resourced in directly querying the DB…

    $_poster = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = 'movie_poster' AND post_id = {$post->ID};", ARRAY_A)[0]['meta_value'];

    But I’ll update my code as your solution is much more clean! Thanks a lot!

  • set the third argument of get_field() Example: get_field('image', false, false)

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

You must be logged in to reply to this topic.