-
-
Notifications
You must be signed in to change notification settings - Fork 95
Admin filters
Extended CPTs provides several controls that can be added to the top of the post type listing screen so your editors can filter the screen by various fields. These controls live next to the default date and category dropdowns which WordPress provides.
Admin filters are specified with the admin_filters
parameter.
register_extended_post_type( 'article', array(
'admin_filters' => array(
'foo' => array(
'title' => 'Foo',
'meta_key' => 'foo',
),
'bar' => array(
'title' => 'Bar',
'meta_search_key' => 'bar',
),
'genre' => array(
'title' => 'Genre',
'taxonomy' => 'genre',
),
),
) );
Displays a select dropdown populated with all the existing values for the given meta key:
'foo' => array(
'title' => 'Foo',
'meta_key' => 'foo',
),
You can also manually specify a list of values if you wish, either as a list or as a callback function:
'foo' => array(
'title' => 'Foo',
'meta_key' => 'foo',
'options' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
),
),
'foo' => array(
'title' => 'Foo',
'meta_key' => 'foo',
'options' => 'get_foo_values',
),
Displays a text input for searching for posts that have that value for the given meta key. Uses a LIKE '%{value}%'
query in SQL.
'foo' => array(
'title' => 'Foo',
'meta_search_key' => 'foo',
),
Displays a checkbox or a select dropdown for filtering by posts which have a meta field with the given key and a non-empty value. This performs a NOT IN ( '', '0', 'false', 'null' )
query for the meta value.
If just one value is passed as the meta_exists
parameter, a checkbox will be shown:
'help_needed' => array(
'meta_exists' => array(
'complete' => 'Complete',
),
),
If multiple values are passed, a select dropdown will be shown for the user to choose from:
'review_type' => array(
'title' => 'Review Type',
'meta_exists' => array(
'complete' => 'Complete',
'broken' => 'Broken',
),
),
Displays a checkbox or a select dropdown for filtering by posts which have a meta field with the given key, regardless of its value. This performs an EXISTS
query for the meta key.
If just one value is passed as the meta_key_exists
parameter, a checkbox will be shown:
'help_needed' => array(
'meta_key_exists' => array(
'help_needed' => 'Help Needed',
),
),
If multiple values are passed, a select dropdown will be shown for the user to choose from:
'review_type' => array(
'title' => 'Review Type',
'meta_key_exists' => array(
'editors_choice' => 'Editors choice',
'help_needed' => 'Help Needed',
),
),
Displays a select dropdown populated with all the available terms for the given taxonomy:
'genre' => array(
'title' => 'Genre',
'taxonomy' => 'genre',
),
Any filter can be restricted so it's only shown to users with a given capability by using the cap
parameter:
'my_filter' => array(
'title' => 'Admin-Only Filter',
'meta_key' => 'foo',
'cap' => 'manage_options',
),
The title
parameter is optional for any filter. If omitted, a title will be generated based on the meta key or taxonomy name. The title is used to label the field as appropriate.
The default
parameter can be used to specify a default value for the filter, which means the post list will be filtered by that value by default.
The meta_query
parameter can be used to pass an array of arguments to the WP_Meta_Query
that's generated when filtering the screen by meta fields.
The label
parameter is optional and will be generated based on the filter type if omitted. This is used for the <label>
that's only shown to screen readers for certain filter types.