45 'hierarchical' => true, |
45 'hierarchical' => true, |
46 'query_var' => 'category_name', |
46 'query_var' => 'category_name', |
47 'rewrite' => $rewrite['category'], |
47 'rewrite' => $rewrite['category'], |
48 'public' => true, |
48 'public' => true, |
49 'show_ui' => true, |
49 'show_ui' => true, |
|
50 'show_admin_column' => true, |
50 '_builtin' => true, |
51 '_builtin' => true, |
51 ) ); |
52 ) ); |
52 |
53 |
53 register_taxonomy( 'post_tag', 'post', array( |
54 register_taxonomy( 'post_tag', 'post', array( |
54 'hierarchical' => false, |
55 'hierarchical' => false, |
55 'query_var' => 'tag', |
56 'query_var' => 'tag', |
56 'rewrite' => $rewrite['post_tag'], |
57 'rewrite' => $rewrite['post_tag'], |
57 'public' => true, |
58 'public' => true, |
58 'show_ui' => true, |
59 'show_ui' => true, |
|
60 'show_admin_column' => true, |
59 '_builtin' => true, |
61 '_builtin' => true, |
60 ) ); |
62 ) ); |
61 |
63 |
62 register_taxonomy( 'nav_menu', 'nav_menu_item', array( |
64 register_taxonomy( 'nav_menu', 'nav_menu_item', array( |
63 'public' => false, |
65 'public' => false, |
87 'new_item_name' => __( 'New Link Category Name' ), |
89 'new_item_name' => __( 'New Link Category Name' ), |
88 'separate_items_with_commas' => null, |
90 'separate_items_with_commas' => null, |
89 'add_or_remove_items' => null, |
91 'add_or_remove_items' => null, |
90 'choose_from_most_used' => null, |
92 'choose_from_most_used' => null, |
91 ), |
93 ), |
|
94 'capabilities' => array( |
|
95 'manage_terms' => 'manage_links', |
|
96 'edit_terms' => 'manage_links', |
|
97 'delete_terms' => 'manage_links', |
|
98 'assign_terms' => 'manage_links', |
|
99 ), |
92 'query_var' => false, |
100 'query_var' => false, |
93 'rewrite' => false, |
101 'rewrite' => false, |
94 'public' => false, |
102 'public' => false, |
95 'show_ui' => false, |
103 'show_ui' => false, |
96 '_builtin' => true, |
104 '_builtin' => true, |
299 * @uses $wp Adds query vars |
307 * @uses $wp Adds query vars |
300 * |
308 * |
301 * @param string $taxonomy Name of taxonomy object |
309 * @param string $taxonomy Name of taxonomy object |
302 * @param array|string $object_type Name of the object type for the taxonomy object. |
310 * @param array|string $object_type Name of the object type for the taxonomy object. |
303 * @param array|string $args See above description for the two keys values. |
311 * @param array|string $args See above description for the two keys values. |
|
312 * @return null|WP_Error WP_Error if errors, otherwise null. |
304 */ |
313 */ |
305 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { |
314 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { |
306 global $wp_taxonomies, $wp; |
315 global $wp_taxonomies, $wp; |
307 |
316 |
308 if ( ! is_array($wp_taxonomies) ) |
317 if ( ! is_array($wp_taxonomies) ) |
320 'capabilities' => array(), |
329 'capabilities' => array(), |
321 'show_in_nav_menus' => null, |
330 'show_in_nav_menus' => null, |
322 ); |
331 ); |
323 $args = wp_parse_args($args, $defaults); |
332 $args = wp_parse_args($args, $defaults); |
324 |
333 |
|
334 if ( strlen( $taxonomy ) > 32 ) |
|
335 return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); |
|
336 |
325 if ( false !== $args['query_var'] && !empty($wp) ) { |
337 if ( false !== $args['query_var'] && !empty($wp) ) { |
326 if ( true === $args['query_var'] ) |
338 if ( true === $args['query_var'] ) |
327 $args['query_var'] = $taxonomy; |
339 $args['query_var'] = $taxonomy; |
328 $args['query_var'] = sanitize_title_with_dashes($args['query_var']); |
340 else |
|
341 $args['query_var'] = sanitize_title_with_dashes($args['query_var']); |
329 $wp->add_query_var($args['query_var']); |
342 $wp->add_query_var($args['query_var']); |
330 } |
343 } |
331 |
344 |
332 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) { |
345 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) { |
333 $args['rewrite'] = wp_parse_args($args['rewrite'], array( |
346 $args['rewrite'] = wp_parse_args($args['rewrite'], array( |
649 global $wpdb; |
662 global $wpdb; |
650 |
663 |
651 $join = ''; |
664 $join = ''; |
652 $where = array(); |
665 $where = array(); |
653 $i = 0; |
666 $i = 0; |
654 |
667 $count = count( $this->queries ); |
655 foreach ( $this->queries as $query ) { |
668 |
|
669 foreach ( $this->queries as $index => $query ) { |
656 $this->clean_query( $query ); |
670 $this->clean_query( $query ); |
657 |
671 |
658 if ( is_wp_error( $query ) ) { |
672 if ( is_wp_error( $query ) ) |
659 return self::$no_results; |
673 return self::$no_results; |
660 } |
|
661 |
674 |
662 extract( $query ); |
675 extract( $query ); |
663 |
676 |
664 if ( 'IN' == $operator ) { |
677 if ( 'IN' == $operator ) { |
665 |
678 |
666 if ( empty( $terms ) ) { |
679 if ( empty( $terms ) ) { |
667 if ( 'OR' == $this->relation ) |
680 if ( 'OR' == $this->relation ) { |
|
681 if ( ( $index + 1 === $count ) && empty( $where ) ) |
|
682 return self::$no_results; |
668 continue; |
683 continue; |
669 else |
684 } else { |
670 return self::$no_results; |
685 return self::$no_results; |
|
686 } |
671 } |
687 } |
672 |
688 |
673 $terms = implode( ',', $terms ); |
689 $terms = implode( ',', $terms ); |
674 |
690 |
675 $alias = $i ? 'tt' . $i : $wpdb->term_relationships; |
691 $alias = $i ? 'tt' . $i : $wpdb->term_relationships; |
754 |
770 |
755 /** |
771 /** |
756 * Transforms a single query, from one field to another. |
772 * Transforms a single query, from one field to another. |
757 * |
773 * |
758 * @since 3.2.0 |
774 * @since 3.2.0 |
759 * @access private |
|
760 * |
775 * |
761 * @param array &$query The single query |
776 * @param array &$query The single query |
762 * @param string $resulting_field The resulting field |
777 * @param string $resulting_field The resulting field |
763 */ |
778 */ |
764 private function transform_query( &$query, $resulting_field ) { |
779 public function transform_query( &$query, $resulting_field ) { |
765 global $wpdb; |
780 global $wpdb; |
766 |
781 |
767 if ( empty( $query['terms'] ) ) |
782 if ( empty( $query['terms'] ) ) |
768 return; |
783 return; |
769 |
784 |
782 INNER JOIN $wpdb->terms USING (term_id) |
797 INNER JOIN $wpdb->terms USING (term_id) |
783 WHERE taxonomy = '{$query['taxonomy']}' |
798 WHERE taxonomy = '{$query['taxonomy']}' |
784 AND $wpdb->terms.{$query['field']} IN ($terms) |
799 AND $wpdb->terms.{$query['field']} IN ($terms) |
785 " ); |
800 " ); |
786 break; |
801 break; |
787 |
802 case 'term_taxonomy_id': |
|
803 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); |
|
804 $terms = $wpdb->get_col( " |
|
805 SELECT $resulting_field |
|
806 FROM $wpdb->term_taxonomy |
|
807 WHERE term_taxonomy_id IN ($terms) |
|
808 " ); |
|
809 break; |
788 default: |
810 default: |
789 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); |
811 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); |
790 $terms = $wpdb->get_col( " |
812 $terms = $wpdb->get_col( " |
791 SELECT $resulting_field |
813 SELECT $resulting_field |
792 FROM $wpdb->term_taxonomy |
814 FROM $wpdb->term_taxonomy |
843 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N |
865 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N |
844 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. |
866 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. |
845 * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not |
867 * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not |
846 * exist then WP_Error will be returned. |
868 * exist then WP_Error will be returned. |
847 */ |
869 */ |
848 function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { |
870 function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { |
849 global $wpdb; |
871 global $wpdb; |
850 $null = null; |
872 $null = null; |
851 |
873 |
852 if ( empty($term) ) { |
874 if ( empty($term) ) { |
853 $error = new WP_Error('invalid_term', __('Empty Term')); |
875 $error = new WP_Error('invalid_term', __('Empty Term')); |
1160 * |
1182 * |
1161 * @param string|array $taxonomies Taxonomy name or list of Taxonomy names |
1183 * @param string|array $taxonomies Taxonomy name or list of Taxonomy names |
1162 * @param string|array $args The values of what to search for when returning terms |
1184 * @param string|array $args The values of what to search for when returning terms |
1163 * @return array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist. |
1185 * @return array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist. |
1164 */ |
1186 */ |
1165 function &get_terms($taxonomies, $args = '') { |
1187 function get_terms($taxonomies, $args = '') { |
1166 global $wpdb; |
1188 global $wpdb; |
1167 $empty_array = array(); |
1189 $empty_array = array(); |
1168 |
1190 |
1169 $single_taxonomy = false; |
1191 $single_taxonomy = ! is_array( $taxonomies ) || 1 === count( $taxonomies ); |
1170 if ( !is_array($taxonomies) ) { |
1192 if ( ! is_array( $taxonomies ) ) |
1171 $single_taxonomy = true; |
1193 $taxonomies = array( $taxonomies ); |
1172 $taxonomies = array($taxonomies); |
|
1173 } |
|
1174 |
1194 |
1175 foreach ( $taxonomies as $taxonomy ) { |
1195 foreach ( $taxonomies as $taxonomy ) { |
1176 if ( ! taxonomy_exists($taxonomy) ) { |
1196 if ( ! taxonomy_exists($taxonomy) ) { |
1177 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
1197 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
1178 return $error; |
1198 return $error; |
1382 if ( 'all' == $fields ) { |
1402 if ( 'all' == $fields ) { |
1383 update_term_cache($terms); |
1403 update_term_cache($terms); |
1384 } |
1404 } |
1385 |
1405 |
1386 if ( empty($terms) ) { |
1406 if ( empty($terms) ) { |
1387 wp_cache_add( $cache_key, array(), 'terms', 86400 ); // one day |
1407 wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); |
1388 $terms = apply_filters('get_terms', array(), $taxonomies, $args); |
1408 $terms = apply_filters('get_terms', array(), $taxonomies, $args); |
1389 return $terms; |
1409 return $terms; |
1390 } |
1410 } |
1391 |
1411 |
1392 if ( $child_of ) { |
1412 if ( $child_of ) { |
1393 $children = _get_term_hierarchy($taxonomies[0]); |
1413 $children = _get_term_hierarchy($taxonomies[0]); |
1394 if ( ! empty($children) ) |
1414 if ( ! empty($children) ) |
1395 $terms = & _get_term_children($child_of, $terms, $taxonomies[0]); |
1415 $terms = _get_term_children($child_of, $terms, $taxonomies[0]); |
1396 } |
1416 } |
1397 |
1417 |
1398 // Update term counts to include children. |
1418 // Update term counts to include children. |
1399 if ( $pad_counts && 'all' == $fields ) |
1419 if ( $pad_counts && 'all' == $fields ) |
1400 _pad_term_counts($terms, $taxonomies[0]); |
1420 _pad_term_counts($terms, $taxonomies[0]); |
1433 |
1453 |
1434 if ( 0 < $number && intval(@count($terms)) > $number ) { |
1454 if ( 0 < $number && intval(@count($terms)) > $number ) { |
1435 $terms = array_slice($terms, $offset, $number); |
1455 $terms = array_slice($terms, $offset, $number); |
1436 } |
1456 } |
1437 |
1457 |
1438 wp_cache_add( $cache_key, $terms, 'terms', 86400 ); // one day |
1458 wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); |
1439 |
1459 |
1440 $terms = apply_filters('get_terms', $terms, $taxonomies, $args); |
1460 $terms = apply_filters('get_terms', $terms, $taxonomies, $args); |
1441 return $terms; |
1461 return $terms; |
1442 } |
1462 } |
1443 |
1463 |
1663 * @uses get_terms() |
1683 * @uses get_terms() |
1664 * @uses wp_parse_args() Turns strings into arrays and merges defaults into an array. |
1684 * @uses wp_parse_args() Turns strings into arrays and merges defaults into an array. |
1665 * |
1685 * |
1666 * @param string $taxonomy Taxonomy name |
1686 * @param string $taxonomy Taxonomy name |
1667 * @param array|string $args Overwrite defaults. See get_terms() |
1687 * @param array|string $args Overwrite defaults. See get_terms() |
1668 * @return int How many terms are in $taxonomy |
1688 * @return int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist. |
1669 */ |
1689 */ |
1670 function wp_count_terms( $taxonomy, $args = array() ) { |
1690 function wp_count_terms( $taxonomy, $args = array() ) { |
1671 $defaults = array('hide_empty' => false); |
1691 $defaults = array('hide_empty' => false); |
1672 $args = wp_parse_args($args, $defaults); |
1692 $args = wp_parse_args($args, $defaults); |
1673 |
1693 |
1800 // Clean the relationship caches for all object types using this term |
1820 // Clean the relationship caches for all object types using this term |
1801 $tax_object = get_taxonomy( $taxonomy ); |
1821 $tax_object = get_taxonomy( $taxonomy ); |
1802 foreach ( $tax_object->object_type as $object_type ) |
1822 foreach ( $tax_object->object_type as $object_type ) |
1803 clean_object_term_cache( $objects, $object_type ); |
1823 clean_object_term_cache( $objects, $object_type ); |
1804 |
1824 |
|
1825 // Get the object before deletion so we can pass to actions below |
|
1826 $deleted_term = get_term( $term, $taxonomy ); |
|
1827 |
1805 do_action( 'delete_term_taxonomy', $tt_id ); |
1828 do_action( 'delete_term_taxonomy', $tt_id ); |
1806 $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); |
1829 $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); |
1807 do_action( 'deleted_term_taxonomy', $tt_id ); |
1830 do_action( 'deleted_term_taxonomy', $tt_id ); |
1808 |
1831 |
1809 // Delete the term if no taxonomies use it. |
1832 // Delete the term if no taxonomies use it. |
1810 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) |
1833 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) |
1811 $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); |
1834 $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); |
1812 |
1835 |
1813 clean_term_cache($term, $taxonomy); |
1836 clean_term_cache($term, $taxonomy); |
1814 |
1837 |
1815 do_action('delete_term', $term, $tt_id, $taxonomy); |
1838 do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); |
1816 do_action("delete_$taxonomy", $term, $tt_id); |
1839 do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term ); |
1817 |
1840 |
1818 return true; |
1841 return true; |
1819 } |
1842 } |
1820 |
1843 |
1821 /** |
1844 /** |
2209 $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
2232 $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
2210 foreach ( $tt_ids as $tt_id ) |
2233 foreach ( $tt_ids as $tt_id ) |
2211 if ( in_array($tt_id, $final_tt_ids) ) |
2234 if ( in_array($tt_id, $final_tt_ids) ) |
2212 $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
2235 $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
2213 if ( $values ) |
2236 if ( $values ) |
2214 $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); |
2237 if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) |
2215 } |
2238 return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error ); |
|
2239 } |
|
2240 |
|
2241 wp_cache_delete( $object_id, $taxonomy . '_relationships' ); |
2216 |
2242 |
2217 do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); |
2243 do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); |
2218 return $tt_ids; |
2244 return $tt_ids; |
2219 } |
2245 } |
2220 |
2246 |
2538 */ |
2564 */ |
2539 function clean_object_term_cache($object_ids, $object_type) { |
2565 function clean_object_term_cache($object_ids, $object_type) { |
2540 if ( !is_array($object_ids) ) |
2566 if ( !is_array($object_ids) ) |
2541 $object_ids = array($object_ids); |
2567 $object_ids = array($object_ids); |
2542 |
2568 |
|
2569 $taxonomies = get_object_taxonomies( $object_type ); |
|
2570 |
2543 foreach ( $object_ids as $id ) |
2571 foreach ( $object_ids as $id ) |
2544 foreach ( get_object_taxonomies($object_type) as $taxonomy ) |
2572 foreach ( $taxonomies as $taxonomy ) |
2545 wp_cache_delete($id, "{$taxonomy}_relationships"); |
2573 wp_cache_delete($id, "{$taxonomy}_relationships"); |
2546 |
2574 |
2547 do_action('clean_object_term_cache', $object_ids, $object_type); |
2575 do_action('clean_object_term_cache', $object_ids, $object_type); |
2548 } |
2576 } |
2549 |
2577 |
2618 * |
2646 * |
2619 * @param int|array $id Term object ID |
2647 * @param int|array $id Term object ID |
2620 * @param string $taxonomy Taxonomy Name |
2648 * @param string $taxonomy Taxonomy Name |
2621 * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id. |
2649 * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id. |
2622 */ |
2650 */ |
2623 function &get_object_term_cache($id, $taxonomy) { |
2651 function get_object_term_cache($id, $taxonomy) { |
2624 $cache = wp_cache_get($id, "{$taxonomy}_relationships"); |
2652 $cache = wp_cache_get($id, "{$taxonomy}_relationships"); |
2625 return $cache; |
2653 return $cache; |
2626 } |
2654 } |
2627 |
2655 |
2628 /** |
2656 /** |
2764 * @param int $term_id The ancestor term: all returned terms should be descendants of $term_id. |
2792 * @param int $term_id The ancestor term: all returned terms should be descendants of $term_id. |
2765 * @param array $terms The set of terms---either an array of term objects or term IDs---from which those that are descendants of $term_id will be chosen. |
2793 * @param array $terms The set of terms---either an array of term objects or term IDs---from which those that are descendants of $term_id will be chosen. |
2766 * @param string $taxonomy The taxonomy which determines the hierarchy of the terms. |
2794 * @param string $taxonomy The taxonomy which determines the hierarchy of the terms. |
2767 * @return array The subset of $terms that are descendants of $term_id. |
2795 * @return array The subset of $terms that are descendants of $term_id. |
2768 */ |
2796 */ |
2769 function &_get_term_children($term_id, $terms, $taxonomy) { |
2797 function _get_term_children($term_id, $terms, $taxonomy) { |
2770 $empty_array = array(); |
2798 $empty_array = array(); |
2771 if ( empty($terms) ) |
2799 if ( empty($terms) ) |
2772 return $empty_array; |
2800 return $empty_array; |
2773 |
2801 |
2774 $term_list = array(); |
2802 $term_list = array(); |
2962 function get_term_link( $term, $taxonomy = '') { |
2990 function get_term_link( $term, $taxonomy = '') { |
2963 global $wp_rewrite; |
2991 global $wp_rewrite; |
2964 |
2992 |
2965 if ( !is_object($term) ) { |
2993 if ( !is_object($term) ) { |
2966 if ( is_int($term) ) { |
2994 if ( is_int($term) ) { |
2967 $term = &get_term($term, $taxonomy); |
2995 $term = get_term($term, $taxonomy); |
2968 } else { |
2996 } else { |
2969 $term = &get_term_by('slug', $term, $taxonomy); |
2997 $term = get_term_by('slug', $term, $taxonomy); |
2970 } |
2998 } |
2971 } |
2999 } |
2972 |
3000 |
2973 if ( !is_object($term) ) |
3001 if ( !is_object($term) ) |
2974 $term = new WP_Error('invalid_term', __('Empty Term')); |
3002 $term = new WP_Error('invalid_term', __('Empty Term')); |
3061 * @param int $post Optional. Post ID or will use Global Post ID (in loop). |
3089 * @param int $post Optional. Post ID or will use Global Post ID (in loop). |
3062 * @param array $args Override the defaults. |
3090 * @param array $args Override the defaults. |
3063 * @return array |
3091 * @return array |
3064 */ |
3092 */ |
3065 function get_the_taxonomies($post = 0, $args = array() ) { |
3093 function get_the_taxonomies($post = 0, $args = array() ) { |
3066 if ( is_int($post) ) |
3094 $post = get_post( $post ); |
3067 $post =& get_post($post); |
|
3068 elseif ( !is_object($post) ) |
|
3069 $post =& $GLOBALS['post']; |
|
3070 |
3095 |
3071 $args = wp_parse_args( $args, array( |
3096 $args = wp_parse_args( $args, array( |
3072 'template' => '%s: %l.', |
3097 'template' => '%s: %l.', |
3073 ) ); |
3098 ) ); |
3074 extract( $args, EXTR_SKIP ); |
3099 extract( $args, EXTR_SKIP ); |
3086 $t['args'] = array(); |
3111 $t['args'] = array(); |
3087 if ( empty($t['template']) ) |
3112 if ( empty($t['template']) ) |
3088 $t['template'] = $template; |
3113 $t['template'] = $template; |
3089 |
3114 |
3090 $terms = get_object_term_cache($post->ID, $taxonomy); |
3115 $terms = get_object_term_cache($post->ID, $taxonomy); |
3091 if ( empty($terms) ) |
3116 if ( false === $terms ) |
3092 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
3117 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
3093 |
3118 |
3094 $links = array(); |
3119 $links = array(); |
3095 |
3120 |
3096 foreach ( $terms as $term ) |
3121 foreach ( $terms as $term ) |
3136 function is_object_in_term( $object_id, $taxonomy, $terms = null ) { |
3161 function is_object_in_term( $object_id, $taxonomy, $terms = null ) { |
3137 if ( !$object_id = (int) $object_id ) |
3162 if ( !$object_id = (int) $object_id ) |
3138 return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); |
3163 return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); |
3139 |
3164 |
3140 $object_terms = get_object_term_cache( $object_id, $taxonomy ); |
3165 $object_terms = get_object_term_cache( $object_id, $taxonomy ); |
3141 if ( empty( $object_terms ) ) |
3166 if ( false === $object_terms ) |
3142 $object_terms = wp_get_object_terms( $object_id, $taxonomy ); |
3167 $object_terms = wp_get_object_terms( $object_id, $taxonomy ); |
3143 |
3168 |
3144 if ( is_wp_error( $object_terms ) ) |
3169 if ( is_wp_error( $object_terms ) ) |
3145 return $object_terms; |
3170 return $object_terms; |
3146 if ( empty( $object_terms ) ) |
3171 if ( empty( $object_terms ) ) |
3209 $term = get_term($object_id, $object_type); |
3234 $term = get_term($object_id, $object_type); |
3210 while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { |
3235 while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { |
3211 $ancestors[] = (int) $term->parent; |
3236 $ancestors[] = (int) $term->parent; |
3212 $term = get_term($term->parent, $object_type); |
3237 $term = get_term($term->parent, $object_type); |
3213 } |
3238 } |
3214 } elseif ( null !== get_post_type_object( $object_type ) ) { |
3239 } elseif ( post_type_exists( $object_type ) ) { |
3215 $object = get_post($object_id); |
3240 $ancestors = get_post_ancestors($object_id); |
3216 if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) ) |
|
3217 $ancestors = $object->ancestors; |
|
3218 else { |
|
3219 while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) { |
|
3220 $ancestors[] = (int) $object->post_parent; |
|
3221 $object = get_post($object->post_parent); |
|
3222 } |
|
3223 } |
|
3224 } |
3241 } |
3225 |
3242 |
3226 return apply_filters('get_ancestors', $ancestors, $object_id, $object_type); |
3243 return apply_filters('get_ancestors', $ancestors, $object_id, $object_type); |
3227 } |
3244 } |
3228 |
3245 |