Last active
January 25, 2018 19:07
-
-
Save obiPlabon/de3e1afcd9056dfede35b25cf65b1540 to your computer and use it in GitHub Desktop.
Restrict hierarchical taxonomy term relation to a certain level.
This file contains hidden or 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 | |
/** | |
* Restrict category term relation to only parent-child | |
* | |
* @see https://wpseek.com/hook/post_edit_category_parent_dropdown_args/ | |
* @see https://wpseek.com/hook/taxonomy_parent_dropdown_args// | |
* | |
* @param array $args | |
* @return array Modified arguments | |
*/ | |
function op_restrict_taxonomy_term_relation( $args ) { | |
if ( 'category' === $args['taxonomy'] ) { | |
$args['depth'] = 1; | |
} | |
return $args; | |
} | |
add_filter( 'post_edit_category_parent_dropdown_args', 'op_restrict_taxonomy_term_relation' ); | |
add_filter( 'taxonomy_parent_dropdown_args', 'op_restrict_taxonomy_term_relation' ); |
This file contains hidden or 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 | |
/** | |
* Restrict hierarchical taxonomy term relation to certain level | |
* | |
* For instance: | |
* 1 for parent - child relation | |
* 2 for grand parent - parent - child / grand child relation | |
* | |
* @see https://wpseek.com/hook/post_edit_category_parent_dropdown_args/ | |
* @see https://wpseek.com/hook/taxonomy_parent_dropdown_args// | |
* | |
* @param array $args | |
* @return array Modified arguments | |
*/ | |
function op_restrict_taxonomy_term_relation( $args ) { | |
/** | |
* Taxonomy name to compare with | |
* or which taxonomy relation you wanna change | |
* | |
* @var string $taxonomy | |
*/ | |
$taxonomy = ''; | |
/** | |
* Taxonomy relation depth | |
* | |
* @var int $depth | |
*/ | |
$depth = 0; | |
if ( $taxonomy === $args['taxonomy'] ) { | |
$args['depth'] = $depth; | |
} | |
return $args; | |
} | |
add_filter( 'post_edit_category_parent_dropdown_args', 'op_restrict_taxonomy_term_relation' ); | |
add_filter( 'taxonomy_parent_dropdown_args', 'op_restrict_taxonomy_term_relation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment