I’ve searched the forums for something similar to this, but I haven;t found anything directly related enough for me to solve this.
I need to dynamically or auto populate an acf text field with the year of a post, either on post submission or post creation. These are standard posts not custom post types.
I’ve created a field called ‘pax_year’ and it is appearing on all posts, I now need to it to fill in with the post year.
I’m aware I’ll need to hook into post update or create hooks, I’m just not sure how to actually populate the field.
Any help with this is greatly appreciated!
What do used depends on why you want to dynamically populate the field and what you want to use the value for.
Do you want to set the default value of the field or is there some other reason you want to set the value? Do you want it to change every time a post is edited or is this something that you want to use on the front end?
Ah, righto! In my case I want to dynamically populate the text field with the date of the post. Then if the post is backdated and updated, that date will then update also.
Thank you so much!
Then you want to use the load value hook https://www.advancedcustomfields.com/resources/acfload_value/. IN this hook you can change the value of the field using the post date. You’ll probably also want to use the update_field() function to update the value as well if the value needs to be changed https://www.advancedcustomfields.com/resources/update_field/.
Please accept my apologies for the late response! That solved it, thank you John! 🙂