Пример #1
0
 public function __construct($args, $taxonomy)
 {
     $term = null;
     if (isset($args['key'])) {
         $term = _mpp_get_term($args['key'], $taxonomy);
     } elseif (isset($args['id'])) {
         $term = _mpp_get_term($args['id'], $taxonomy);
     }
     if ($term && !is_wp_error($term)) {
         $this->id = $term->term_id;
         $this->tt_id = $term->term_taxonomy_id;
         //to make it truely multilingual, do not use the term name instead use the registered label if available
         if (isset($args['label'])) {
             $this->label = $args['label'];
         } else {
             $this->label = $term->name;
         }
         $this->slug = str_replace('_', '', $term->slug);
         //remove _ from the slug name to make it private/public etc
         if (isset($args['labels']['singular_name'])) {
             $this->singular_name = $args['labels']['singular_name'];
         } else {
             $this->singular_name = $this->label;
         }
         if (isset($args['labels']['plural_name'])) {
             $this->plural_name = $args['labels']['plural_name'];
         } else {
             $this->plural_name = $this->label;
         }
     }
 }
Пример #2
0
/**
 * Check if a term already exists for gallery
 * 
 * @global type $wpdb
 * @param type $term
 * @param type $taxonomy
 * @param type $parent
 * @return int existing term id
 */
function mpp_term_exists($term, $taxonomy = '', $parent = 0)
{
    $term = mpp_strip_underscore($term);
    return _mpp_get_term($term, $taxonomy);
    /*
    	global $wpdb;
    
    	$select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
    
    	$tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";
    
    	if ( is_numeric( $term ) ) {
    		if ( 0 == $term )
    			return 0;
    		$where = 't.term_id = %d';
    		if ( !empty( $taxonomy ) )
    			return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A );
    		else
    			return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
    	}
    
    	$term = trim( wp_unslash( $term ) );
    
    	$slug = $term;
    
    	$where			 = 't.slug = %s';
    	$where_fields	 = array( $slug );
    
    	if ( !empty( $taxonomy ) ) {
    
    		$where_fields[] = $taxonomy;
    
    
    		if ( $result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $where_fields ), ARRAY_A ) )
    			return $result;
    	}
    
    
    	return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug ) );
    */
}