std value not loading with block

Support MB Blocks std value not loading with block

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #49597
    Paul WenzelPaul Wenzel
    Participant

    Sorry if this is a duplicate - my first post didn't seem to save,,,

    'std' value is not loading when the block is added to a gutenberg page. Tried std 2 different ways (including both for illustrative purposes - I tried both individually) Am I missing something?

    $meta_boxes[] = [
            'id' => $block_id,
            'title' => 'Post - Vertical List',
            'type' => 'block',
            'icon' => '',
            'category' => 'layout',
            'supports' => [
                'anchor' => true,
            ],
            'render_template' => get_stylesheet_directory() . '/partials/custom-blocks/posts/post-vertical-list/post-vertical-list.php',
            'enqueue_style' => get_stylesheet_directory_uri() . '/partials/custom-blocks/posts/post-vertical-list/post-vertical-list.css',
            'fields' => [
                [
                    'id' => $block_prefix . 'posts_per_page',
                    'name' => 'Number of Posts',
                    'type' => 'number',
    				'std' => 5,
                    'min' => 1,
                    'max' => 12,
                ],
                $fields['custom_name']['custom_name_text'],
                $fields['custom_name']['show_name_on_frontend'],
                [
                    'id' => $block_prefix . 'include_images',
                    'name' => 'Include Images in Lower Posts',
                    'type' => 'switch',
                    'style'     => 'rounded',
                    'off_label' => 'No',
                    'on_label'  => 'Yes',
                    'std' => 'No',
                ],
                $fields['auto_pull'],
                $fields['taxonomy_terms_category'],
                $fields['taxonomy_terms_tags']
            ],
            'std' => [
                $block_prefix . 'posts_per_page' => 5
            ]
        ];
    #49600
    PeterPeter
    Moderator

    Hello Paul,

    Thanks for reaching out.

    Can you please remove other fields and recheck this?

    
            'fields' => [
                [
                    'id' => $block_prefix . 'posts_per_page',
                    'name' => 'Number of Posts',
                    'type' => 'number',
    				'std' => 5,
                    'min' => 1,
                    'max' => 12,
                ]
            ],
    

    and please note that the default value will work if the custom block doesn't have any value, otherwise, it doesn't work.

    #49601
    Paul WenzelPaul Wenzel
    Participant

    Okay, after some back and forth:

    The taxonomy_terms_category is the culprit, but I can't figure out why.

    'fields' => [
                [
                    'id' => $block_prefix . 'posts_per_page',
                    'name' => 'Number of Posts',
                    'type' => 'number',
                    'std' => 5,
                    'min' => 1,
                    'max' => 12,
                ],
                $fields['custom_name']['custom_name_text'],
                $fields['custom_name']['show_name_on_frontend'],
                [
                    'id' => $block_prefix . 'include_images',
                    'name' => 'Include Images in Lower Posts',
                    'type' => 'switch',
                    'style'     => 'rounded',
                    'off_label' => 'No',
                    'on_label'  => 'Yes',
                    'std' => 'No',
                ],
                
            'auto_pull' => [
                'id' => $block_prefix . 'auto_pull',
                'name' => 'Auto Pull',
                'type' => 'radio',
                'options' => [
                    '' => 'None',
                    'category' => 'Category',
                    'tag' => 'Tag',
                ],
            ],
            'taxonomy_terms_category' => [
                'id' => $block_prefix . 'taxonomy_terms_category',
                'name' => 'Category',
                'type' => 'taxonomy',
                'taxonomy' => ['category'],
                'field_type' => 'select_advanced',
                'placeholder' => 'Select category',
                'multiple' => false,
                'hidden' => [$block_prefix . 'auto_pull', '!=', 'category'],
    
            ],
            'taxonomy_terms_tags' => [
                'id' => $block_prefix . 'taxonomy_terms_tags',
                'name' => 'Tag',
                'type' => 'taxonomy',
                'taxonomy' => ['post_tag'],
                'field_type' => 'select_advanced',
                'placeholder' => 'Select tag',
                'multiple' => false,
                'query_args' => [
                    'hide_empty' => true,
                    'number' => 0
                ],
                'hidden' => [$block_prefix . 'auto_pull', '!=', 'tag'],
    
            ],

    If I remove that, it works fine. Any other combination without that works fine, and any combination with that breaks the number_of_posts std (and the std on other fields if I set it, like in include images...)

    Any idea why?

    #49602
    Paul WenzelPaul Wenzel
    Participant

    Update: Changing the category options type from taxonomy to taxonomy_advanced fixed the issue.

    #49603
    PeterPeter
    Moderator

    Hello,

    The taxonomy field type will set the post term, like the default Category box of WordPress, so it doesn't work with a custom block or a subfield inside a group field. Refer to the documentation
    https://docs.metabox.io/fields/taxonomy/

    Thanks.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.