20 var
$icon =
'dashicons-category';
23 $this->label = esc_html__(
'Post Category',
'gk-gravityview' );
25 add_action(
'gravityview/edit-entry/render/before', array( $this,
'add_edit_entry_post_category_choices_filter' ) );
27 add_action(
'gravityview/edit-entry/render/after', array( $this,
'remove_edit_entry_post_category_choices_filter' ) );
29 add_action(
'gravityview/edit_entry/after_update', array( $this,
'set_post_categories' ), 10, 2 );
31 parent::__construct();
46 $entry = GFAPI::get_entry( $entry_id );
49 if( empty( $post_id ) ) {
55 $post_category_fields = GFAPI::get_fields_by_type(
$form,
'post_category' );
57 if( $post_category_fields ) {
59 $updated_categories = array();
61 foreach ( $post_category_fields as
$field ) {
63 $field_cats = RGFormsModel::get_field_value( $field );
64 $field_cats = is_array( $field_cats ) ? array_values( $field_cats ) : (array)$field_cats;
66 $updated_categories = array_merge( $updated_categories, array_values( $field_cats ) );
70 $updated_categories = array_filter( $updated_categories );
77 $append = apply_filters(
'gravityview/edit_entry/post_categories/append',
false );
79 $return = wp_set_post_categories( $post_id, $updated_categories, $append );
95 add_filter(
'gform_post_category_choices', array( $this,
'edit_entry_post_category_choices' ), 10, 3 );
108 remove_filter(
'gform_post_category_choices', array( $this,
'edit_entry_post_category_choices' ), 10 );
131 $post_categories = wp_get_post_categories( $post_id, array(
'fields' =>
'ids' ) );
134 foreach ( $choices as &$choice ) {
135 $choice[
'isSelected'] = in_array( $choice[
'value'], array_values( $post_categories ) );
144 if(
'edit' === $context ) {
145 return $field_options;
152 $field_options[
'new_window'][
'requires'] =
'link_to_term';
154 return $field_options;
Modify field settings by extending this class.
edit_entry_post_category_choices( $choices, $field, $form_id)
Always show the live Category values.
add_edit_entry_post_category_choices_filter()
Add filter to show live category choices in Edit Entry.
add_field_support( $key, &$field_options)
if(gravityview() ->plugin->is_GF_25()) $form
gv_map_deep( $value, $callback)
Maps a function to all non-iterable elements of an array or an object.
set_post_categories( $form=array(), $entry_id=0)
Update the post categories based on all post category fields.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
remove_edit_entry_post_category_choices_filter()
Remove filter to show live category choices in Edit Entry.
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
new GravityView_Field_Post_Category