Pubblicare programmaticamente un post (custom post type) con campi personalizzati
Ho un custom post type 'Participant' con molti campi personalizzati. Ho anche un form con campi di input corrispondenti che l'utente deve compilare. Quando invia il form, voglio che venga generato un nuovo post con ogni campo personalizzato contenente il valore scelto dall'utente.
È possibile farlo e se sì, come?

Utilizza wp_insert_post() e add_post_meta(), in questo modo:
// inserisci il post e imposta la categoria
$post_id = wp_insert_post(array (
'post_type' => 'your_post_type',
'post_title' => $your_title,
'post_content' => $your_content,
'post_status' => 'publish',
'comment_status' => 'closed', // se preferisci
'ping_status' => 'closed', // se preferisci
));
if ($post_id) {
// inserisci i meta del post
add_post_meta($post_id, '_your_custom_1', $custom1);
add_post_meta($post_id, '_your_custom_2', $custom2);
add_post_meta($post_id, '_your_custom_3', $custom3);
}

oggi puoi semplicemente aggiungere campi meta tramite la chiave meta_input in wp_insert_post: 'meta_input' => ['_your_custom_1' => $custom1, '_your_custom_2' => custom2]

Ottimo punto @Andreas, suggerisco di aggiungerlo come nuova risposta e lasciare che inizi a ricevere voti positivi. Dovrebbe essere la risposta corretta ora.

Oltre alla ottima risposta di @webaware sopra, questo può essere gestito a partire da WordPress 4.4.0 interamente tramite la chiamata wp_insert_post:
$post_id = wp_insert_post(array (
'post_content' => $content,
'post_title' => $title,
'post_type' => 'your_custom_post_type',
'post_status' => 'publish',
// semplice array chiave/valore
'meta_input' => array(
'your_custom_key1' => 'your_custom_value1',
'your_custom_key2' => 'your_custom_value2'
// e così via ;)
)
));
if ($post_id) {
// ha funzionato :)
}

Questo può essere ottenuto abbastanza facilmente utilizzando il plugin Gravity Forms. Puoi creare un modulo che popola un Custom Post Type nel backend. Il post può essere impostato per apparire come bozza o come pubblicato. Nessun problema nell'aggiungere campi personalizzati. Nel mio caso, l'ho utilizzato per raccogliere testimonianze dei clienti.
