Hi there,
I have created a custom field for an URL, and I would like to set the post URL of the field to be created as a default value. How can I do this? What exactly do I have to enter in the field for default Value?
thanks in advance
Jutta
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jutta,
Unfortunately no this won't be possible to do.
You can only set the field's default value in the custom fields settings page, which can only be set to a fixed text there.
Thanks,
Shane
Hi Shane, what code would I add for the post-url?
thanks!
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jutta,
You should be able to do it with the hook below.
https://developer.wordpress.org/reference/hooks/save_post/
This hook will trigger when you update/save the post on the backend.
Now you will also need to make use of the update_post_meta function.
https://developer.wordpress.org/reference/functions/update_post_meta/
Here is an example that you can modify to craft a solution for this case.
https://wordpress.stackexchange.com/questions/284749/set-the-value-of-custom-field-when-post-is-published-or-updated
Thanks,
Shane