Domanda

Sto cercando di fare un'importazione personalizzata da un CMS personalizzato a Wordpress. Guardando i file di esportazione / importazione in wordpress, posso ottenere partita più della struttura. Anche se, manca i rapporti di tassonomie personalizzate e messaggi durante l'esportazione / importazione.

C'è una correzione per questo o sarebbe più facile per script di importazione non utilizzo di wordpress? Piuttosto, SQL di scrittura personalizzato per gestire il tutto.

Inoltre, come sto sviluppando questo nuovo sito il contenuto del vecchio sito (CMS personalizzati) è ancora in fase di aggiornamento. Ci sarà un congelamento pochi giorni prima del lancio, dove posso fare un altro discarica db e di reimportazione. Anche se, il problema che sto prevedendo è che ho bisogno di cancellare tutti i messaggi e le relazioni e reimportare il contenuto. C'è un modo semplice per cancellare tutti i messaggi e le relazioni per prevenire eventuali duplicati e reimportare il contenuto?

È stato utile?

Soluzione

It shouldn't be hard to add handling for custom post types or taxonomies within a custom importer for WordPress. You'll just need to make sure that your custom post types and taxonomies are registered before the importer runs. Once registered, you can use wp_insert_post() and wp_set_object_terms() on these custom types. This will likely end up being a much better solution than trying to write custom SQL as it fills in a lot of the extra fields that aren't always obvious, like term object counts, etc.

Whenever I'm working on a script to import data from another system, I've always created nuke functions, for the reason you mentioned, and just because importing data is always a bunch of trial and error. The function usually just consists of a single loop to call wp_delete_post() for each post. Depending on the import, I may also add another one to call wp_delete_term() on each term in the database.

$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type in ('post', 'attachment', [...other post types])");
foreach($post_ids as $post_id) {
    wp_delete_post($post_id, true);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top