Last active
August 29, 2015 14:06
-
-
Save isotrope/ac7464ecf82e77c3faae to your computer and use it in GitHub Desktop.
Importing a CPT with its Custom Taxonomies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* User: Michal | |
* Date: 2014-09-23 | |
* Time: 10:34 AM | |
*/ | |
require( '../../../../wp-load.php' ); | |
$data_json = json_decode( file_get_contents( 'data.json' ), true ); | |
foreach ( $data_json as $entry ) { | |
// Insert the post | |
$post_id = wp_insert_post( $entry['post'] ); | |
// Set its taxonomy terms | |
if ( isset( $entry['tax1'] ) && $entry['tax1'] != '' ) { | |
wp_set_post_terms( $post_id, $entry['tax1'], 'your_taxonomy_name1', false ); | |
} | |
// Set its taxonomy terms | |
if ( isset( $entry['tax2'] ) && $entry['tax2'] != '' ) { | |
wp_set_post_terms( $post_id, $entry['tax2'], 'your_taxonomy_name2', false ); | |
} | |
} | |
flush_rewrite_rules( true ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment