Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 0.47 KB | Hits: 31 | Expires: Never
Copy text to clipboard
  1. <?php
  2. $custom_cat = get_post_meta($post_id, 'category-field', true);
  3. $postdata = wp_get_single_post($post_id, ARRAY_A);
  4. $postcats = $postdata['post_category'];
  5. if ( is_term( $custom_cat , 'category' ) ){
  6. $custom_cat_id = get_cat_id($custom_cat);
  7. }else{
  8. $custom_cat_id = wp_create_category($custom_cat);
  9. }
  10. $postcats[] = $custom_cat_id;
  11. $postdata = array( "ID" => $post_id, "post_category" => $postcats);
  12. sanitize_post($postdata,"db");
  13. wp_update_post($postdata);
  14. ?>