Advertisement
jeffrose

WP Taxonomy Meta

Mar 26th, 2011
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1.  
  2. add_action( 'edited_rp_booking_types', 'rp_taxonomy_meta_update_post', 10, 2 );
  3.  
  4. function rp_taxonomy_meta_create_post( $term_id, $tt_id ){
  5.     global $wpdb;
  6.    
  7.     $postID = wp_insert_post( array( 'post_title' => "taxonomy-meta-term-{$term_id}", 'post_type' => 'rp_taxonomy_meta' ) );
  8.    
  9.     return $postID;
  10. }
  11.  
  12. function rp_taxonomy_meta_update_post( $term_id, $tt_id ){
  13.     global $wpdb;
  14.    
  15.     if ( !$post_id = post_exists( "taxonomy-meta-term-{$term_id}" ) ){
  16.         $post_id = rp_taxonomy_meta_create_post( $term_id, $tt_id );
  17.     }
  18.    
  19.     if ( $post_id === 0 || is_null( $post_id ) ){
  20.         return;
  21.     }
  22.    
  23.     $meta_key = 'booking_type_color';
  24.     $meta_value = esc_attr( $_POST["booking_type_color"] );
  25.    
  26.     update_post_meta( $post_id, $meta_key, $meta_value);
  27. }
  28.  
  29. function rp_taxonomy_meta_get_meta( $term_id ){
  30.    
  31.     $post_id = post_exists( "taxonomy-meta-term-{$term_id}" );
  32.    
  33.     if ( $post_id ){
  34.         return get_post_meta( $post_id, 'booking_type_color' );
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement