Saltar navegación

[Resuelto] Set the post URL as default value to custom field

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Zona horaria del colaborador: America/Jamaica (GMT-05:00)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por - 4 years, 7 months ago.

Asistido por: Shane.

Autor
Mensajes
#2299131

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

#2299243

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

#2303419

Hi Shane, what code would I add for the post-url?

thanks!

#2304865

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