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