Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Andrew Misplon

    (@misplon)

    Hi stevesicherman

    Thanks for reaching out.

    Greg our lead developer is currently travelling for a few days. I’ll see if Braam who in charge of the Widget Bundle can lend a hand here.

    Plugin Author Braam Genis

    (@braam-genis)

    If you’re referring to the repeater form field provided by the SiteOrigin Widget Bundle, then there’s certainly no trick to saving an array, it should Just Work?. ??

    You can inspect the $_POST variable (using a breakpoint or var_dump) in siteorigin_panels_save_post function in siteorigin-panels.php to see whether or not your array is present.

    Thread Starter Steve

    (@stevesicherman)

    Sorry I was just referring to my own custom widgets.

    When I print my array from the Widgets screen, I get this:

    Array
    (
        [0] => 246
        [1] => 198
    )

    When I print my array from a widget inserted into Page Builder, I get this:

    Array
    (
        [] => Array
            (
                [0] => 246
                [1] => 198
            )
    
    )

    Page Builder is nesting the array when multiple values are selected from my multiple select (but it doesn’t so this if only one value is selected).

    <select id="<?php echo $this->get_field_id( 'post_id' ); ?>" name="<?php echo $this->get_field_name( 'post_id' ) . '[]'; ?>" multiple="multiple">
    				<?php
    				$args = array( 'posts_per_page'   => -1, 'post_type' => 'page' );
    				$array_post_id = $instance['post_id'];
    				$myposts = get_posts( $args );
    				foreach ( $myposts as $post ){
    					setup_postdata( $post );
    				    echo '<option value="'. $post->ID .'" ', is_array($array_post_id ) && in_array( $post->ID,  $array_post_id ) ? ' selected="selected"' : '','>'. $post->post_title . '</option>';
    				}
    				?>

    Do you see any issues with the above?

    Thread Starter Steve

    (@stevesicherman)

    When I assign the variable an array and assign it a single value, Page Builder still generates an empty key-

    Array
    (
        [] => 246
    )
    Thread Starter Steve

    (@stevesicherman)

    This seems to be caused by appending the ‘[]’ characters to the select’s name attribute. Page Builder nests the array in a null key when multiple values are saved (can’t get rid of that though, the Widgets section (Appearance > Widgets) requires the brackets).

    Plugin Support Andrew Misplon

    (@misplon)

    (Greg has our initial Page Builder developer docs up: https://siteorigin.com/docs/page-builder/)

    Plugin Support Andrew Misplon

    (@misplon)

    The team is off for the holidays. I’ll ask Greg or Braam to jump back in here again as soon as they are able. Please feel free to give it a bump in a week or so if we haven’t gotten back to you yet.

    Thanks for your ongoing support.

    Plugin Author Braam Genis

    (@braam-genis)

    Hey stevesicherman

    I don’t see any obvious problems with what you’ve posted, but it’s difficult to troubleshoot the problem without context of what you’re trying to achieve.

    We’re working on getting developer docs fleshed out soon. So perhaps it will be a bit easier to make sense of things when we publish those.

    Thread Starter Steve

    (@stevesicherman)

    If you try naming a form element xyz[] you may see the issue, PB won’t save the data to an array in the same method as WP will save the data to an array on the widgets screen. Without a fix it’ll be difficult getting any repeater field working in PB (although if you know of one that works I’d love to see what they’re doing right).

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Widget not saving’ is closed to new replies.