Last active
November 16, 2023 21:47
-
-
Save faisalahammad/48d748643fe1f8ff401aaf66abcb9bdc to your computer and use it in GitHub Desktop.
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
| add_filter( 'gform_post_category_args', 'allow_specific_categories', 10, 2 ); | |
| function allow_specific_categories( $args, $field ) { | |
| // add allowed category IDs | |
| $allowed_categories = array( 12, 34, 56 ); | |
| if ( isset( $args['include'] ) && is_array( $args['include'] ) ) { | |
| $args['include'] = array_merge( $args['include'], $allowed_categories ); | |
| } else { | |
| $args['include'] = $allowed_categories; | |
| } | |
| return $args; | |
| } |
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
| add_filter( 'gform_post_category_args', 'change_categories', 10, 2 ); | |
| function change_categories( $args, $field ) { | |
| // add your categories IDs (seperate by comma) | |
| $exclude_categories = '11,32,33'; | |
| if ( isset( $args['exclude'] ) && ! empty( $args['exclude'] ) ) { | |
| $args['exclude'] .= ',' . $exclude_categories; | |
| } else { | |
| $args['exclude'] = $exclude_categories; | |
| } | |
| return $args; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment