Home › Forums › Feature Requests › Reduce Queries – Save Image URL not ID
The problem: All of the wp_get_attachment functions require 2 database calls per image (from what I can tell by testing it out), so that means any image referenced by an ACF field += 2 queries. This can be a lot if you have a fairly large repeater (or a gallery).
Since we know what image we could save the URL (and any other associated data) in a post_meta field instead of only saving the attachment ID.
I know this is possible by using a text field instead of an image field, but then the image selector is lost, and it’s harder for the WP admins/editors to input images.
Solution: What I think would be great is a new field that lets you use the image selector to saves the URLs (full and all pre-sized ) and meta in the post_meta table, perhaps serialized into a single field.
Has anyone attempted to build a field that does something like this? Is it a foolish idea?
Pro/Con
Pros:
Cons:
Hi @wilirius
I think you can create a text field that will hold the serialized image data. After that, you can use the acf/save_post hook to update the serialized image text field when you updating the post. You can update the field using the update_field() function.
I hope this helps.
Ahh yes that’s a great idea! I think I saw something like that before for saving the GPS lat/lng from the map field.
Just to verify:
Hi @wilirius
I think that’s perfect. Don’t forget that you can use serialize() and unserialize() functions.
I hope this helps 🙂
The topic ‘Reduce Queries – Save Image URL not ID’ is closed to new replies.
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.