Home › Forums › Front-end Issues › Storing variable to custom field
Bit of a weird one I’m not too sure how to word this, or what I’m lucking for so I was just after some pointers.
Within a loop I have a YouTube play count pulled in and store in the variable $plays, is there any known way of storing this value into a custom field and say every 4 hours updating this value as it changes.
Cheers for any pointers on this one.
Hi @jduffell
When is this play count fetched? Whenever someone starts up the youtube video or whenever the page is loaded?
As for saving the value to a custom field that’s very simple. You can use ACF function update_field()
.
http://www.advancedcustomfields.com/resources/update_field/
Hi @jonathan cheers, I was actually just looking at this.
It’s currently pulled into the loop itself and output from a variable within that.
^JD
Alright,
So is your issue solved or do you still need help? Not sure from your response 🙂
Hi Jonathan, marked as solved now.
The update_field was perfect for storing the value, I’m just a little concerned about how I’ve gone about it, I don’t really want to use a cron job but I was wondering if you perhaps know of any better ways of storing a value to posts on a regular basis but perhaps not on every page load.
Cheers for any pointers.
^JD
Well the only other way I can think of is that you could use Transients which expires. When it expires = update it again.
https://codex.wordpress.org/Transients_API
Not sure it’s the right way to go tho unless you’re confident in keeping the information in a transient rather than as a meta value.
Otherwise I see no reason why you couldn’t use cron. 🙂
The topic ‘Storing variable to custom field’ 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.