Created
August 24, 2016 15:15
-
-
Save camaech/362075f08a4c9917cf1da94b048a4364 to your computer and use it in GitHub Desktop.
Import WP Term Category Meta Data
This file contains hidden or 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 | |
/** Loads the WordPress Environment and Template */ | |
require ('./wp-blog-header.php'); | |
$import_data = array_map('str_getcsv', file('CategoriesImport.csv')); | |
$product_cats = get_terms( | |
array( | |
'taxonomy' => array('product_cat', 'industry_solution_category') | |
) | |
); | |
$count = 0; | |
$wpseo_tax_data = get_option('wpseo_taxonomy_meta'); | |
$all_categories = $wpseo_tax_data['product_cat']; | |
foreach($product_cats as $single) { | |
$category_name = $single->name; | |
$import_key = array_search( $category_name, array_column( $import_data, 0 ) ); | |
if($import_key != 0) { | |
$count ++; | |
if ( isset( $import_data[ $import_key ][4] ) ) { | |
$all_categories[ $single->term_id ]["wpseo_title"] = clean( $import_data[ $import_key ][4] ); | |
} | |
if ( isset( $import_data[ $import_key ][5] ) ) { | |
$all_categories[ $single->term_id ]["wpseo_focuskw"] = clean( $import_data[ $import_key ][5] ); | |
} | |
if ( isset( $import_data[ $import_key ][6] ) ) { | |
$all_categories[ $single->term_id ]["wpseo_desc"] = clean( $import_data[ $import_key ][6] ); | |
} | |
if ( isset( $import_data[ $import_key ][7] ) ) { | |
$term_update_args = array( 'description' => clean( $import_data[ $import_key ][7] ) ); | |
$update = wp_update_term( $single->term_id, 'product_cat', $term_update_args ); | |
} | |
if ( isset( $import_data[ $import_key ][8] ) ) { | |
update_term_meta( $single->term_id, 'detailed_description', clean( $import_data[ $import_key ][8] ) ); | |
} | |
} | |
} | |
$wpseo_tax_data['product_cat'] = $all_categories; | |
$option_update = update_option('wpseo_taxonomy_meta', $wpseo_tax_data); | |
//echo $count; | |
//echo $option_update; | |
function clean($string) { | |
return preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment