47 private function __construct( $term )
49 if ( !is_null( $term ) ) {
50 $term_exists = term_exists( $term->name, $term->taxonomy, $term->parent );
52 foreach ( $term as $property => $value ) {
53 $this->{$property} = $value;
55 $this->permalink = get_term_link( $term );
77 public static function term( $term,
$taxonomy =
false, $output = OBJECT, $filter =
'raw',
$parent =
false )
82 $sql = sprintf(
'SELECT t.*, tt.description, tt.taxonomy FROM %s AS t LEFT JOIN %s AS tt ON ( tt.term_id = t.term_id )', $wpdb->terms, $wpdb->term_taxonomy );
83 if ( is_numeric( $term ) ) {
84 $sql .= sprintf(
' WHERE t.term_id = %s', $term );
86 elseif ( is_string( $term ) ) {
87 $sql .= sprintf(
' WHERE t.slug = "%s"', $term );
89 elseif ( is_object( $term ) ) {
90 $sql .= sprintf(
' WHERE t.term_id = "%s"', $term->term_id );
96 $row = $wpdb->get_row( $sql );
97 if ( is_null( $row ) ) {
100 $term = $row->term_id;
105 if ( is_object( $term ) || is_numeric( $term ) ) {
106 $term = get_term( $term,
$taxonomy, $output, $filter );
109 $by = (
'%' === substr( $term, 0, 1 ) ) ?
'name' :
'slug';
110 $term = ltrim( $term,
'%' );
111 $term = get_term_by( $by, $term,
$taxonomy, $output, $filter );
114 if ( !is_wp_error( $term ) ) {
117 if (
true ===
$parent && !empty( $instance->parent ) ) {
118 $instance->term_parent = self::term( $instance->parent,
$taxonomy );
152 if ( is_a( $term,
'WPDKTerm' ) ) {
157 while ( !empty( $term->parent ) ) {
158 $term = self::term( $term->parent, $term->taxonomy );
159 $result = self::term( $term->term_id, $term->taxonomy );
377 $this->_taxonomy = $taxonomy;
382 'hide_empty' =>
true,
383 'exclude' => array(),
384 'exclude_tree' => array(),
385 'include' => array(),
390 'hierarchical' =>
true,
394 'pad_counts' =>
false,
397 'cache_domain' =>
'core'
400 foreach ( $defaults as $property => $value ) {
401 $this->{$property} = $value;
416 $args = (array)$this;
419 unset( $args[
'WPDKTerms_taxonomy'] );
420 $terms = get_terms( $this->_taxonomy, $args );
437 $args = (array)$this;
439 unset( $args[
'WPDKTerms_taxonomy'] );
440 $terms = get_terms( $this->_taxonomy, $args );
441 foreach ( $terms as $term ) {
442 $term->children = $this->
tree( $term );
446 $args = (array)$this;
448 unset( $args[
'WPDKTerms_taxonomy'] );
449 $terms = get_terms( $this->_taxonomy, $args );
450 foreach ( $terms as $term ) {
451 $term->children = $this->
tree( $term );
472 $from = $this->
term( $term );
473 $stack = array( $from );
474 $id_parent = $from->parent;
476 while ( !empty( $id_parent ) ) {
477 $stack[] = $term = $this->
term( $id_parent );
478 $id_parent = $term->parent;
481 return array_reverse( $stack );