Tuesday, 10 September 2013

PHP Array to solve space issue

PHP Array to solve space issue

I have this PHP code
case "category": {
// CHECK IF THE CATEGORY ALREADY EXISTS
if ( is_term( $val, THEME_TAXONOMY ) ){
$term = get_term_by('name', str_replace("_"," ",$val),
THEME_TAXONOMY);
$catID = $term->term_id;
}else{
$args = array('cat_name' => str_replace("_"," ",$val) );
$term = wp_insert_term(str_replace("_"," ",$val), THEME_TAXONOMY,
$args);
if(is_array($term) && isset($term['term_id']) &&
!isset($term['errors'][0]) ){
$catID = $term['term_id'];
}elseif(isset($term->term_id)){
$catID = $term->term_id;
}
}
$my_post['post_category'] = array($catID);
} break;
it was used to import categories in wordpress but issue is as code is
showing it is replace _ with so I want to import multiple categories so
how can I use an array to do it?
I'm importing multiple categories name like abs,test,test12 . So it was
just importing as it is then I did this abs_test_test12 . And it just
removed _ with space and imported. However each name is different
category. It should import each name after a comma or underscore as a new
category name. –

No comments:

Post a Comment