-
-
Save wpsmith/f153b7ab746417d73b7d to your computer and use it in GitHub Desktop.
PHP: WordPress get_terms_fields for taxonomy.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'get_terms_fields', 'wps_get_terms_fields', 10, 3 ); | |
| /** .. Known filter; removed docs for brevity **/ | |
| function wps_get_terms_fields( $selects, $args, $taxonomies ) { | |
| if ( 'slug=>name' === $args['fields'] ) { | |
| return array( 't.slug', 't.name', 'tt.count', 'tt.taxonomy' ); | |
| } | |
| return $selects; | |
| } | |
| add_filter( 'get_terms_fields_terms', 'wps_get_terms_fields_terms', 10, 4 ); | |
| /** | |
| * Filter the given taxonomy's terms for terms with posts (items) of publish post_status. | |
| * | |
| * @param array $terms Array of terms (maybe cached) for the given taxonomy. | |
| * @param string $fields Current fields to return from args fields parameter. | |
| * @param array $taxonomies An array of taxonomies. | |
| * @param array $args An array of get_terms() arguments. | |
| * | |
| * @return array $terms Maybe filtered terms. | |
| */ | |
| function wps_get_terms_fields_terms( $terms, $fields, $taxonomies, $args ) { | |
| if ( 'slug=>name' === $$fields ) { | |
| $_terms = array(); | |
| foreach( $terms as $term ) { | |
| $_terms[ $term->slug ] = $term->name; | |
| } | |
| } | |
| return $terms; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment