Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use complex set_default_value with dynamic data not updated after save post #1191

Open
khalilr2k opened this issue Oct 19, 2023 · 0 comments

Comments

@khalilr2k
Copy link

Version

  • Carbon Fields: 3.1
  • WordPress: 6.0.3
  • PHP: 8.2

I created a COMPLEX field with set_default_value function. The values is queried from existing terms in WordPress Taxonomy.
When entering the Post edit, I see the values as excepted. but when create a new term. then return to edit post page. I not seen the new term.

Expected Behavior

After create a new term, should be updated in post edit.

Actual Behavior

After create a new term, is not shown in post edit

Container definition

$cats=get_terms(['taxonomy'=>'dish_category','hide_empty'=>false,'parent'=>0]);
$parent_categories = [];
if(!empty($cats)){
    foreach($cats as $ind=>$cat){
        $par = [];
        $par['parent_category'] = $cat->name;
        $scats =get_terms(['taxonomy'=>'dish_category','hide_empty'=>false,'parent'=>$cat->term_id]);
        $par['sub_categories']  = [];
        foreach($scats as $single_subcategory) {
            $par['sub_categories'][] = [
                'sub_category' => $single_subcategory->name,
            ];
        }
        $parent_categories[] = $par;
    }
}

Field::make( 'complex',  'main_menu_categories_order', 'סידור קטגוריות בתפריט' )
->add_fields( array(
    Field::make( 'text', 'parent_category' )
    ->set_attribute( 'readOnly', 'true' ),
    Field::make( 'complex', 'sub_categories' )
    ->add_fields( array(
        Field::make( 'text', 'sub_category' )
        ->set_attribute( 'readOnly', 'true' ),
    ))
    ->set_classes( 'delete-remove-icon' )
    ->set_duplicate_groups_allowed( false )
    ->set_header_template( '<%- sub_category %>' )
    ->set_collapsed( true )
))
->set_default_value( $parent_categories )
->set_classes( 'delete-remove-icon' )
->set_duplicate_groups_allowed( false )
->set_header_template( '<%- parent_category %>' )
->set_collapsed( true ) 

Steps to Reproduce the Problem

  1. enter to post edit, then reorder the complex field, then save the post.
  2. go to terms, and add new one
  3. return to post edit, and the new new isn't there

Comments

I tried to clear all meta of the field manually (by the PHPMYADMIN). the new term shown there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant