Remove Pagination in Appearance -> Menus -> Categories

As per Stackoverflow Stackoverflow

Ok after reading through the source code I found that the number of categories returned in the edit menu section is hardcoded to 50 on line 613 of \wp-admin\includes\nav-menu.php

// Paginate browsing for large numbers of objects.
    $per_page = 50;
    $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
    $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;

In order to override the default of 50 per page you can set the number to ” to instruct the query to return all categories. Add the following code to your functions.php file.

add_filter( 'get_terms_args', 'show_all_categories_admin_nav_menu', 10, 2);

    function show_all_categories_admin_nav_menu( $args, $taxonomies ) {
        if( reset($taxonomies) === 'category' ) {
            $args['number'] = '';
        }

        return $args;
    }

If you set the number to blank it still shows the pagination even though it’s showing all the categories.

There’s also a filter called terms_clauses that exists in which you can remove the SQL LIMIT clause from the query but this didn’t seem to have any affect on the query.

add_filter('terms_clauses', 'modify_terms_clauses', 10, 3);

function modify_terms_clauses( $clauses, $taxonomies, $args ) {
    if( reset($taxonomies) === 'category' ) {
        $clauses['limits'] = '';
    }

    return $clauses;
}

Leave a Comment