wp_insert_post () o simile per il tipo di post personalizzato
-
-
Hai registrato un `customposttype` denominato` custom_post`prima di usare questa chiamata?Have you registered a `custom post type` named as `custom_post` before using this call?
- 0
- 2013-07-18
- Rohit Pande
-
sì è registratoyes its registered
- 0
- 2013-07-18
- rashid
-
nonimporta,funziona,c'era unbugminorenelfile,questoframmentoesatto è corretto.basta sostituire "custom_post" coniltipo dipost ditua scelta!never mind, its working, there was a minor bug in the file, this exact snippet is correct. just replace 'custom_post' with post type of your choosing!
- 0
- 2013-07-18
- rashid
-
3 risposta
- voti
-
- 2013-07-18
wp_insert_post () compilerà unelencopredefinito di questimail l'utente ètenuto afornireiltitoloe il contenuto,altrimentiil la scrittura del databasefallirà.
$id = wp_insert_post(array( 'post_title'=>'random', 'post_type'=>'custom_post', 'post_content'=>'demo text' ));
wp_insert_post() will fill out a default list of these but the user is required to provide the title and content otherwise the database write will fail.
$id = wp_insert_post(array( 'post_title'=>'random', 'post_type'=>'custom_post', 'post_content'=>'demo text' ));
-
- 2014-06-24
Puòesserefatto utilizzandoil seguente codice: -
Perinserire unnuovopostper untipopersonalizzato
$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', // if you prefer 'ping_status' => 'closed', // if you prefer ));
Dopo averinseritoilpost,verrà restituito unid delpost dallafunzioneprecedente.Ora,se vuoiinserire qualsiasimetainformazioni delpost con questopost,puoi utilizzareil seguenteframmento di codice.
if ($post_id) { // insert post meta 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); }
It can be done using the following code :-
To enter a new post for a custom type
$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', // if you prefer 'ping_status' => 'closed', // if you prefer ));
After inserting the post, a post id will be returned by the above function. Now if you want to enter any post meta information w.r.t this post then following code snippet can be used.
if ($post_id) { // insert post meta 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); }
-
Ilparametro "meta_input"puòessere utilizzatonell'array "wp_insert_post",per aggiungerei meta campi,invece di utilizzare "add_post_meta"in seguito.The 'meta_input' parameter can be used in the 'wp_insert_post' array, to add meta fields, instead of using 'add_post_meta' afterward.
- 0
- 2019-03-10
- AncientRo
-
Grazieperilpost.@AncientRow,puoifornire unesempio cheincluda `meta_input`?Thanks for the post. @AncientRow, can you provide an example including `meta_input`?
- 0
- 2020-04-22
- Pegues
-
- 2015-03-10
Ho scoperto che l'utilizzo di
isset()
mi consentiva di utilizzarewp_insert_post()
suitipi dipostpersonalizzati:if ( !isset( $id ) ) { $id = wp_insert_post( $new, true ); }
I found using
isset()
allowed me to usewp_insert_post()
on custom post types:if ( !isset( $id ) ) { $id = wp_insert_post( $new, true ); }
-
Performattare correttamenteil codicenella risposta (o domanda),evidenziarloe fare clic su ** {} ** sopra la casella dimodifica.To properly format code in your answer (or question), highlight it and click **{}** above the edit box.
- 0
- 2015-03-10
- Gabriel
Ènecessarioinserire oggetti ditipopostpersonalizzato dal codice.Non sono statoin grado di aggiungere utilizzandoilmetodopredefinito
creainvece unnormalepost.