Home › Forum › Problemi Vari con WP › Associazione categoria a post via script
-
AutorePost
-
-
8 Febbraio 2012 alle 10:08 #20634m4rko80Partecipante
Ciao a tutti, altro giorno altro problema:)
Inserisco posts via script con tanto di categoria e come esito finale dalla pagina admin vedo i miei post con le categorie abbinate in fase di creazione.
Ho notato pero’ che se uso un plugin per mostrare solo dei post per categoria, nella select di categoria non ho nulla nella lista a differenza di quando creo una categoria creando un post direttamente da admin.
Uso wp_insert_post($post) passando in $post l’array coi dati relativi ai campi necessari e prima di creare un post ho già creato le categorie con:
$cat_slug = trim(strtolower(str_replace(' ','-',$categoria)));
$my_cat = array('cat_name' => $categoria, 'category_description' => '', 'category_nicename' => $cat_slug, 'category_parent' => '');
$my_cat_id = wp_insert_category( $my_cat ,true);
Creo il post:
//$array_id_category_post lo ricavo estraendo le categorie in base alla lista che mi ritrovo nel feed e recupero l'id di ognuna avendole create prima se non già esistenti
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_category' => $array_id_category_post, //lista id delle categorie associate.
'post_content' => $content, //The full text of the post.
'post_date' => $data_format, //[ Y-m-d H:i:s ] The time post was made.
'post_date_gmt' => $data_format, //[ Y-m-d H:i:s ] The time post was made, in GMT.
'post_status' => 'publish', //Set the status of the new post.
'post_title' => $news->title, //The title of your post.
'post_type' => 'post',
'tags_input' => TAG_FEED_NEWS //For tags - nome del mio tag
);
Manca un passaggio per rendere funzionanti queste categorie?
Nella pagina admin All posts vedo tutti i post con le categorie associate e tag
Grazie
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.