Home » Hooks » restrict_manage_posts

The restrict_manage_posts hook is a powerful tool in WordPress that allows developers to add custom filters to the admin panel’s post listing pages. It is used to modify the query string of the list table for custom sorting, searching, and filtering of posts or custom post types.

In plain English, this hook enables developers to add custom filters to the posts listing page in the WordPress admin panel. For instance, if you have a custom post type for movies and you want to add a filter by genre, this hook allows you to do that.

The restrict_manage_posts hook is a very useful tool in creating custom back-end functionality for WordPress sites. It can be used to help users quickly find the content they need, without having to scroll through long lists of posts.

Here is an example usage code for the restrict_manage_posts hook:

function add_custom_filter() {
  global $typenow;

  if ( $typenow == 'movie' ) {
    // create the filter dropdown
    echo '<select name="movie_genre">';
    echo '<option value="">Select genre</option>';
    echo '<option value="action">Action</option>';
    echo '<option value="comedy">Comedy</option>';
    echo '<option value="drama">Drama</option>';
    echo '</select>';

add_action( 'restrict_manage_posts', 'add_custom_filter' );

In this example, we are checking if the current post type is ‘movie’. If it is, we are adding a dropdown filter for the ‘movie_genre’ taxonomy. This is just one way to use this hook, and the possibilities are endless.

Learn More on

Register an account to save your snippets or go Pro to get more features.