Untitled
By: a guest | Feb 9th, 2010 | Syntax:
None | Size: 0.47 KB | Hits: 31 | Expires: Never
<?php
$custom_cat = get_post_meta($post_id, 'category-field', true);
$postdata = wp_get_single_post($post_id, ARRAY_A);
$postcats = $postdata['post_category'];
if ( is_term( $custom_cat , 'category' ) ){
$custom_cat_id = get_cat_id($custom_cat);
}else{
$custom_cat_id = wp_create_category($custom_cat);
}
$postcats[] = $custom_cat_id;
$postdata = array( "ID" => $post_id, "post_category" => $postcats);
sanitize_post($postdata,"db");
wp_update_post($postdata);
?>