Skip to content

Instantly share code, notes, and snippets.

@faisalahammad
Last active November 16, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faisalahammad/48d748643fe1f8ff401aaf66abcb9bdc to your computer and use it in GitHub Desktop.
Save faisalahammad/48d748643fe1f8ff401aaf66abcb9bdc to your computer and use it in GitHub Desktop.
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;
}
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