The wp_terms_checklist_args
filter allows you to modify the arguments array in wp_terms_checklist
, which is located in wp-admin/includes/template.php. wp_terms_checklist
is the taxonomy-independent version of wp_category_checklist
and only works with hierarchical taxonomies.
It accepts two arguments:
- array
$args
The arguments array (seewp_terms_checklist
for the defaults - int
$post_id
The post id
Example:
Let’s say you have a hierarchical taxonomy called ‘Media Categories’ — with a slug of media_cats
— that you’re using with media attachments. And let’s say you don’t want the selected categories to float to the top of the box (the default behavior).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable 'checked_ontop' for Media Categories taxonomy | |
* | |
* @see wp_terms_checklist() | |
* | |
* @param array $args An array of arguments. | |
* @param int $post_id The post id. | |
* | |
* @return array The arguments array. | |
*/ | |
function wpdocs_no_top_float( $args, $post_id ) { | |
// If the taxonomy is set and equals 'media_cats' | |
if ( isset( $args['taxonomy'] ) && 'media_cats' == $args['taxonomy'] ) | |
$args['checked_ontop'] = false; | |
return $args; | |
} | |
add_filter( 'wp_terms_checklist_args', 'wpdocs_no_top_float', 10, 2 ); |
View the code example on Gist.