Last active
September 2, 2016 09:23
-
-
Save elimn/d023f0678a5800af74452c98673091dc to your computer and use it in GitHub Desktop.
MT | ECP | Limit the number of tags visible to ECP widget filters in WP Admin
This file contains 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
/* | |
* Limits the number of tags visible to the TEC widget filter in WP Admin | |
* | |
* Useful for when your site has loads of tags. Which causes WP Admin > Widgets | |
* page to load very slowly or not at all. | |
*/ | |
function tribe_limit_get_terms( $terms, $taxonomy, $query_vars, $term_query ) { | |
if( ! is_admin() ) return $terms; | |
$num_of_tags_to_show = 50; | |
$target_tax = array( 'post_tag' ); | |
$wp_screen = get_current_screen(); | |
if( $wp_screen->base !== 'widgets' ) return $terms; | |
if( $taxonomy !== $target_tax ) return $terms; | |
return array_slice( $terms, 0, $num_of_tags_to_show); | |
} | |
add_filter( 'get_terms', 'tribe_limit_get_terms', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment