8

I am looking for a way to show all post tags on post edit screen/tags sidebox in WordPress admin section. By default WordPress shows 45 most used tags but I need a way to list all tags there or at least increase this limit.

I found similar question here Showing all tags in admin -> edit post. But it suggests to edit/modify WordPress core files which is not what I really want. Because upgrading WordPress will be a huge problem then.

I also could not find anything in Google search. So is there are way to list all or more than 45 tags on post edit page.

9

I'd say the easiest way to do it is use the get_terms_args filter and unset the number limit if the context is right (the AJAX request to get the tag cloud):

function wpse_64058_all_tags ( $args ) {
    if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] === 'get-tagcloud' )
        unset( $args['number'] );
    return $args;
}

add_filter( 'get_terms_args', 'wpse_64058_all_tags' );

Note: In the edit box the link will still read "Choose from the most used tags", even though we're now displaying all of them.

Edit: As @bonger suggested, you could determine the post type from the referer:

if ( $qs = parse_url( wp_get_referer(), PHP_URL_QUERY ) ) {
    parse_str( $qs, $args );

    if ( ! empty( $args['post_type'] ) )
        $post_type = $args['post_type'];
    elseif ( ! empty( $args['post'] ) )
        $post_type = get_post_type( $args['post'] );
    else
        $post_type = 'post';
}
  • 2
    +1. Would be nice if it can be run only for specific post types, but I'm afraid is not so easy. Regarding "Choose from the most used tags", is possible to use gettext filter to change it. – gmazzap Jan 12 '15 at 12:18
  • @G.M. Yes, we can change text. But I am okay with "Choose from the most used tags". Although I am wondering why can we not check for post type here? Is this executed before everything else. – Robert hue Jan 12 '15 at 15:14
  • 1
    There is no way to determine the post type within the context the filter executes. You could see which post type the taxonomy is attached to, but that's only useful if it's the only post type. The only other option is to remove the default post_tags_meta_box handler and replace it with your own. – TheDeadMedic Jan 12 '15 at 15:29
  • Though you could use $_SERVER['HTTP_REFERER'] to find out the post_type if you really wanted to. – bonger Jan 12 '15 at 17:26
  • 1
    You could use wp_get_referer(). Keep in mind that it returns false as well in the case if the current request and the previous are equal (whoever had that idea: slow clap). – kaiser Jan 14 '15 at 20:05
0

Addition to TheDeadMedic's answer, to show ALL tags:

if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] === 'get-tagcloud' ) {
    unset( $args['number'] );
    $args['hide_empty'] = 0;
}
return $args;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.