Saltar navegación

[Resuelto] How to create custom posts through code?

This support ticket is created hace 5 años, 8 meses. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel hace 5 años, 8 meses.

Asistido por: Nigel.

Autor
Mensajes
#1234252

I have created a custom post and fields. Now I need to create these posts via an automation. I need some help/direction in creating posts through php code. I can use WordPress function to create posts but I need some guidance on adding field data and taxonomy to the posts via code.

#1234382

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi there

You would be using the standard WordPress API for this rather than any specific Toolset functions.

As you already know, you use wp_update_post to save the standard fields of a post (https://developer.wordpress.org/reference/functions/wp_update_post/).

To save custom fields, you would use update_post_meta (https://developer.wordpress.org/reference/functions/update_post_meta/). The one thing that you need to be aware of here is that if you have set up custom fields with Types, then the corresponding meta key has a 'wpcf-' prefix, so a 'priority' custom field would have a key of 'wpcf-priority'.

For taxonomies I assume you already created the custom taxonomies and terms, and will be programmatically assigning them. For that there are a number of functions you could use, with wp_set_post_terms your best starting point: https://developer.wordpress.org/reference/functions/wp_set_post_terms/