The post_edit_category_parent_dropdown_args WordPress PHP filter allows you to modify the arguments for the taxonomy parent dropdown on the Post Edit page.
Usage
add_filter( 'post_edit_category_parent_dropdown_args', 'my_custom_function', 10, 1 ); function my_custom_function( $args ) { // Your custom code here return $args; }
Parameters
- $args (array): Array of arguments to generate parent dropdown.
- taxonomy (string): Name of the taxonomy to retrieve.
- hide_if_empty (bool): True to skip generating markup if no categories are found. Default 0.
- name (string): Value for the ‘name’ attribute of the select element. Default “new{$tax_name}_parent”.
- orderby (string): Which column to use for ordering terms. Default ‘name’.
- hierarchical (bool|int): Whether to traverse the taxonomy hierarchy. Default 1.
- show_option_none (string): Text to display for the “none” option. Default “— {$parent} —”, where $parent is ‘parent_item’ taxonomy label.
More information
See WordPress Developer Resources: post_edit_category_parent_dropdown_args
Examples
Change the ‘name’ attribute of the select element
Modify the ‘name’ attribute of the select element to ‘custom_parent’.
add_filter( 'post_edit_category_parent_dropdown_args', 'change_name_attribute', 10, 1 ); function change_name_attribute( $args ) { $args['name'] = 'custom_parent'; return $args; }
Sort categories by ID
Order categories by ID instead of the default ‘name’.
add_filter( 'post_edit_category_parent_dropdown_args', 'sort_categories_by_id', 10, 1 ); function sort_categories_by_id( $args ) { $args['orderby'] = 'ID'; return $args; }
Display custom text for ‘none’ option
Change the text displayed for the “none” option to ‘No Parent Category’.
add_filter( 'post_edit_category_parent_dropdown_args', 'change_none_option_text', 10, 1 ); function change_none_option_text( $args ) { $args['show_option_none'] = 'No Parent Category'; return $args; }
Hide empty categories
Skip generating markup for empty categories.
add_filter( 'post_edit_category_parent_dropdown_args', 'hide_empty_categories', 10, 1 ); function hide_empty_categories( $args ) { $args['hide_if_empty'] = true; return $args; }
Disable hierarchy traversal
Disable the traversal of taxonomy hierarchy.
add_filter( 'post_edit_category_parent_dropdown_args', 'disable_hierarchy_traversal', 10, 1 ); function disable_hierarchy_traversal( $args ) { $args['hierarchical'] = 0; return $args; }