Tutorials WordPress

An Easy Way to Filter Posts in WordPress Admin

Updated

Written by

Dave Warfel

Reading Time

4 minutes

If you buy something from one of our links, we may earn a commission.

When working with posts in your WordPress admin area, you might be looking for a way to filter your posts. By default, WordPress includes a few filter options via dropdown menus at the top of the page. You can also filter posts by clicking on the name of a category, tag or author.

Show Categories, Tags & Authors in Screen Options

Before you can click on various links on your “Posts” screen to filter them, you need to make sure they are displayed in your list of posts. Look in the top-right corner for “Screen Options,” and make sure Author, Categories & Tags are checked.

WordPress screen options on posts

This is somewhat limiting, however, because you can only filter by one single option at a time. The exception is if you use the dropdowns at the top, you can filter by both Month AND Category. But you’re still limited to only ONE category and ONE month.

Some examples of more complex filtering could include:

  • View posts with a specific category OR a specific tag
  • View posts in any one of 3 different categories
  • View only published posts by one author
  • View drafts in a particular category, only by one author
  • View scheduled posts to be published in January 2015

Query Parameters

When you click on “Published,” take notice how your URL changes. It will look like this:

http://yoursite.com/wp-admin/edit.php?post_status=publish&post_type=post

Explaining query parameters in detail is beyond the scope of this article, but you can probably understand what is happening here. Query parameters are being used to filter posts. In this example, post_type=post is only displaying posts (not pages, or any other custom post type), and post_status=publish is only displaying published posts (not drafts or scheduled posts).

Similarly, if you click on the name of one of your categories, you’ll see a URL like this (I clicked on “Plugins”):

http://yoursite.com/wp-admin/edit.php?category_name=plugins

Filter posts in WordPress admin area

List of Query Parameters You Can Use

Using a bunch of different query parameters, you can create your own variations for more complex filtering. You would enter a custom URL into your address bar to achieve your desired filtering. Here’s a list of all the query parameters that you can use, along with what each one means.

As long as your URL starts with this, you can use all of the following parameters:

http://yoursite.com/wp-admin/edit.php
Query Parameter Possible Values Description Allow Multiple?
post_type post
page
{custom-post-type}
The type of content or post type NO
post_status all
publish
draft
future
trash
The post’s status. “Future” will show posts that are scheduled to be published in the future. NO
author {ID} The author’s ID YES
category_name {category-slug} The category’s slug YES
tag {tag-slug} The tag’s slug YES
m YYYYMM Month: Must be entered in the format YYYYMM.
Ex: 201401 for January 2014.
NO
show_sticky 1 Shows posts marked as “sticky.” You either use it with a value of 1, or don’t include it at all. NO

Allow Multiple

If we’ve indicated that you can filter using multiple values, you can do so using commas between values in your URL. (Refer to the table above)

If you want to view all posts in the “Plugins” OR “WordPress Admin” categories, use the following:

http://yoursite.com/wp-admin/edit.php?category_name=plugins,news

You can do the same thing with tags. To view all posts with either the “Keyboard Shortcuts” OR “Sass” tags, use the following:

http://yoursite.com/wp-admin/edit.php?tag=keyboard-shortcuts,sass

To view posts by either author 1 OR author 3 (1 and 3 are the author’s ID), use the following:

http://yoursite.com/wp-admin/edit.php?author=1,3

OR vs. AND

Using commas between values will find posts in either one OR the other. To find posts with BOTH value 1 AND value 2, use the plus sign (+). For example, to find posts with BOTH tags “keyboard shortcuts” AND “sass”:

http://yoursite.com/wp-admin/edit.php?tag=keyboard-shortcuts+sass

Combine Multiple Filtering Options

You can combine several filtering options all at once. For example, you could view posts:

  • scheduled to publish in the future (post_status=future)
  • with either the “WP Engine” or “Hosting” tag (tag=wp-engine,hosting)
  • by either author 3 or author 4 (author=3,4)
  • only in January 2014 (m=201401)
http://yoursite.com/wp-admin/edit.php?post_status=future&tag=wp-engine,hosting&author=3,4&m=201401

Dave Warfel

LinkedIn  •  X (Twitter)Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

17 responses to “An Easy Way to Filter Posts in WordPress Admin”

  1. Eloy Avatar
    Eloy

    Hi!
    Thanks for the post. It’s a very useful information to easily customize posts listings. I was trying to filter posts from a custom type using one of his meta fields.
    Is it possible?
    Thank you.

    1. Dave Warfel Avatar

      Hi Eloy. Thanks :-)

      I don’t think custom field filtering is natively supported, however, here are two options for you:

      1. I found some code on Stack Exchange to implement something like this on your own. If you’re comfortable with PHP, give it a shot.

      2. There’s a WordPress plugin called Admin Columns that might be able to create what you’re looking for. I’ve used it before and it’s AWESOME.

      The free version will allow you to modify what info shows up on the post listing page in the admin. The pro version takes it one step further and allows you to filter your post listings in a variety of different ways, including custom fields.

      Let me know if either of those work out for you.

  2. Eloy Avatar
    Eloy

    Hi, Dave.
    I found something that did the trick:

    function meta_key_filter( $query ) {
    
            if ( $query->is_admin && isset( $_GET['parameter_name'] ) ) 
    		$meta_key_query = array(
    			array(
    				'key' => 'meta_key',
    				'value' => $_GET['parameter_name'],
    			)
    		);
    		$query->set( 'meta_query', $meta_key_query );
    	}
    	
    	return $query;
    }
    
    add_action( 'pre_get_posts', 'meta_key_filter' );

    So, I can use my on GET filter for showing attendants to a course:

    wp-admin/edit.php?post_type=attendants&course_id=480

    Next step is implementing the option #1.

    Thanks for you help!

    1. Dave Warfel Avatar

      Awesome! Thanks for sharing, Eloy.

    2. aksl Avatar
      aksl

      Hi, what is the option 1 ?

      Can we have the parameter in edit.php ?

      Thanks

    3. Dave Warfel Avatar

      aksl – I think the option 1 that Eloy was referring to was this:

      1. I found some code on Stack Exchange to implement something like this on your own. If you’re comfortable with PHP, give it a shot.

  3. ChrisFewings Avatar
    ChrisFewings

    OR…AND
    You can use + for AND in the URL

    1. Adrian Avatar
      Adrian

      Hi

      Can I ask where the + goes if I have category “book” and nested under that I have sub-category “fiction”? For “book” it will look like

      http://yoursite.com/wp-admin/edit.php?category_name=book

      but how do I get “and” category_name=fiction. I have tried

      http://yoursite.com/wp-admin/edit.php?category_name=book+category_name=fiction and
      http://yoursite.com/wp-admin/edit.php?category_name=book+fiction

      Both of these return 0 posts.

      Thank you

    2. Dave Warfel Avatar

      Hi Adrian,

      I just tried Chris’ suggestion, and it does appear you can use the + sign to serve as an AND operator. Your second link should be the correct syntax:

      http://yoursite.com/wp-admin/edit.php?category_name=book+fiction

      Double-check you have the correct category names. You can do this by…
      – In the main post list (unfiltered), click the blue link under your Category column that says “book.”
      – Look at the URL
      – Note the correct category_name
      – Then do the same thing for “fiction.”

      Let me know if that works for you.

  4. Adrian Avatar
    Adrian

    Hi Dave

    Thank you for taking the time to respond. It does indeed work. Your response convinced me to check my work. I had been incorrectly using using the category names rather than the slugs (clearly says slug above ;-) which were for me; book and book-fiction. This is great. Just what I need to achieve what I am messing with.

    This is much easier than messing with $query IMO on admin pages. Now to find the PHP to create a menu like

    Books
    All Books
    Fiction Books
    Non-Fiction Books
    Add Book

    Early stages learning for me and this is really a great blog post.

    Regards

    Adrian

    1. Dave Warfel Avatar

      Awesome! Glad you realized what the issue was, and got it working.

      I’m a beginner at PHP, just like you. Best of luck with the code for turning it into a menu. If you have a blog or publish your code somewhere, I’d be happy to include it in this post for those looking to take things a step further.

      Enjoy your weekend :-)

  5. Adrian Avatar
    Adrian

    Dave

    I do not have a blog or anywhere I publish stuff. I got the menu bit working and found a piece of code to pre-select (click) the book category when adding a book. This code works for ,my simple purposes but it needs some more work because:

    1) the Books menu does not open in the way that Posts opens
    2) it would be great when edit.php is called if the title said “Books” instead of “Posts”
    3) it would be great when post-new.php is called if the title said “New Book” instead of “New Post”.

    Anyway long and short custom post types would address all of the above and before anyone asks – no I will not be using custom post types in this case :-) For reasons I won’t go into I am using regular post types here.

    For my testing purposes I created a hierarchy of categories;

    book
    – book-fiction
    – book-non-fiction

    I added the following to my child theme functions.php for easy testing. Though I will later move the code to a plugin. The following code is not theme specific so it does not belong in functions.php. Some quotes might not cut and paste properly below but there is enough here to figure things out :-)

    /* See http://w-shadow.com/blog/2012/11/20/pre-select-category-for-new-post/comment-page-1/#comment-777526
    Neat way to pre-select a category when adding a post */

    function preselect_post_category() {
    if ( isset($_GET[‘category_id’]) && is_numeric($_GET[‘category_id’]) ) {
    $catId = intval($_GET[‘category_id’]);
    ?>

    jQuery(function() {
    var catId = ;
    jQuery(‘#in-category-‘ + catId).click();
    });

    <?php
    }
    }

    /* Add action to call preselect_post_category on adding a new post and if catgeory_id is set then use jQuery to "click" the category
    in the categories right side bar widget. This is very useful if using Advanced Custom Fields with categories because an ACF field
    group will display on the Add Posts page if an ACF rule exists for the "clicked" category. */

    add_action('admin_footer-post-new.php', 'preselect_post_category');

    function my_custom_menus() {

    /* Add top level "Books" menu option to the admin sidebar
    From https://codex.wordpress.org/Administration_Menus
    add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); */

    add_menu_page(
    'Books', // page title – though unclear where this is actually displayed
    'Books', // menu title
    'edit_posts', // capability
    'top-level-book-menu', // slug
    '', // function – not used here
    '', // no icon specified
    3 // menu position
    );

    /* Add sub menu options to the "Books" top level menu option
    From https://codex.wordpress.org/Administration_Menus
    add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function); */

    add_submenu_page(
    'top-level-book-menu', // parent menu slug
    'All Books', // page title – though unclear where this is actually displayed
    'All Books', // menu title
    'edit_posts', // capability
    'edit.php?category_name=book', // slug – this is the bit of code the menu will access
    '' // function – not used here
    );

    add_submenu_page(
    'top-level-book-menu', // parent menu slug
    'Fiction Books', // page title – though unclear where this is actually displayed
    'Fiction Books', // menu title
    'edit_posts', // capability
    'edit.php?category_name=book+book-fiction', // slug – this is the bit of code the menu will access
    '' // function – not used here
    );

    add_submenu_page(
    'top-level-book-menu', // parent menu slug
    'Non-Fiction Books', // page title – though unclear where this is actually displayed
    'Non-Fiction Books', // menu title
    'edit_posts', // capability
    'edit.php?category_name=book+book-non-fiction', // slug – this is the bit of code the menu will access
    '' // function – not used here
    );

    add_submenu_page(
    'top-level-book-menu', // parent menu slug
    'Add Book', // page title – though unclear where this is actually displayed
    'Add Book', // menu title
    'edit_posts', // capability
    'post-new.php?category_id=44', // slug. 44 is the id of the book category
    '' // function – not used here
    );

    remove_submenu_page('top-level-book-menu', 'top-level-book-menu'); // prevent high level menu also appearing as sub menu item

    } // my_custom_menus

    add_action('admin_menu', 'my_custom_menus');

  6. jeremy Avatar
    jeremy

    Hello,

    Is it possible to filter so that when I search something it only looks INTO the post title?

    Thanks !

    1. Dave Warfel Avatar

      Jeremy — The only way I’m aware of to achieve that is with the Admin Columns plugin. It’s an amazing tool if you do a lot of work on post edit screens, and it’s also great for super-fast inline editing of custom fields, WooCommerce data, ACF fields, etc.

  7. amer Avatar
    amer

    Hi….please I need to ask about the parameters that i’m doing filtering according to them. Does anyone know how these parameters are passing? and in which file

    1. Dave Warfel Avatar

      I don’t know all the technical details behind how these work. To find the actual file that makes it happen, you’d have to search the /wp-admin/ directly. One of those files likely has the code that makes the database calls to filter the Posts table.

  8. amer Avatar
    amer

    Ok thank you anyway and please if anyone knows how this is functioning let me know

Leave a Comment