Create author and taxonomy filters in WordPress admin page

Tạo bộ lọc theo tác giả và taxonomy trong trang quản trị WordPress

The article provides a guide on creating custom filters in the WordPress admin page to manage a large number of blog posts. It explains how to filter articles by author and taxonomy. The instructions include adding code to the functions.php file in the theme or child theme. The author filter allows users to filter posts by a specific author, while the taxonomy filter enables filtering based on custom post types. The article concludes by emphasizing the usefulness of these filters for effective post management and encourages readers to comment, share, and explore more WordPress tips.

Managing a plethora of blog posts on WordPress can be a daunting task, right? So, how can you make this process easier in your WordPress admin? Well, I’ve got you covered in this article. I’ll walk you through creating custom filters in the WordPress admin page, specifically focusing on filters by author and taxonomy.

Filter articles by author

After following my instructions, you’ll see a customized filter by author like the image below:
create filter by author

This filter isn’t limited to just Posts; it also works for Pages and custom post types. Simply add the code snippet below to your theme or child theme’s functions.php file:

function hk_filter_by_the_author() {
    $params = array(
        'name' => 'author',
        'show_option_all' => 'All authors'
    );

    if ( isset($_GET['user']) )
        $params['selected'] = $_GET['user'];

    wp_dropdown_users( $params );
}

add_action('restrict_manage_posts', 'hk_filter_by_the_author');

With this, you can easily filter posts by a specific author in your WordPress admin. How cool is that?

Filter posts by taxonomy

Sure, WordPress has a default category filter for Posts, but what about other custom post types on your site? Let me guide you through creating taxonomy filters for those post types. Check out the result I achieved in the image below:
taxonomy filter

See also  Change WordPress default upload directory for maximum efficiency.

Add the code snippet below to your theme’s functions.php file to create taxonomy filters:

function hk_posts_taxonomy_filter() {
    global $typenow;
    if ($typenow == 'your-post-type-slug') {
        $taxonomy_names = array('taxonomy1', 'taxonomy2');
        foreach ($taxonomy_names as $single_taxonomy) {
            // Code to display taxonomy filter
        }
    }
}

add_action('restrict_manage_posts', 'hk_posts_taxonomy_filter');

Remember to replace 'your-post-type-slug' with your own post type slug and 'taxonomy1', 'taxonomy2' with your taxonomy slugs.

That’s it! By implementing these filters, you can efficiently manage your posts and save time. If you found this article helpful, please leave a comment and share it with others. Also, consider exploring more WordPress tips and following us on Facebook for additional insights. Happy filtering! ✌️

5/5 - (1 vote)

Related posts