Skip to content

Instantly share code, notes, and snippets.

@elimn
Last active September 2, 2016 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elimn/d023f0678a5800af74452c98673091dc to your computer and use it in GitHub Desktop.
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
/*
* 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