Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_edit_category_parent_dropdown_args filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
May 2, 2023
5 minutes read

post_edit_category_parent_dropdown_args filter

Filters the arguments for the taxonomy parent dropdown on the Post Edit page.


apply_filters( 'post_edit_category_parent_dropdown_args', array $parent_dropdown_args )

Description

This hook is used filter the arguments for taxonomy parent dropdown on post edit page.

It gives a dropdown of all taxonomy with same parent, for given arguments.

Parameters

  • $parent_dropdown_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.

Live Example

To run the hook, copy the example below.

$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); 
                         
if ( !empty( $parent_dropdown_args ) ) { 
                         
   // everything has led up to this point... 
                         
} 
  

The following example is for adding a hook callback.

// define the post_edit_category_parent_dropdown_args callback 
function filter_post_edit_category_parent_dropdown_args( $parent_dropdown_args ) { 
    // make filter magic happen here... 
    return $parent_dropdown_args; 
}; 
         
// add the filter 
add_filter( 'post_edit_category_parent_dropdown_args', 'filter_post_edit_category_parent_dropdown_args', 10, 1 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_edit_category_parent_dropdown_args', 'filter_post_edit_category_parent_dropdown_args', 10, 1 ); 
Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.