WordPress.org

Ready to get started?Download WordPress

Forums

OptionTree
[resolved] [closed] Update or add new list item from front end (5 posts)

  1. Wee Beastie
    Member
    Posted 1 year ago #

    This is less of a support issue, and more of a development problem that I could use some guidance on, if anyone has any thoughts.

    I'd like to edit/add new list items using a form on the front end. Adding new list items is by far the more important of the two objectives here.

    Updating meta from the front end for simpler fields like text, radio, etc. is fairly straightforward using something like:

    update_post_meta( $post->ID, 'my_meta_id', $my_meta_update);

    and just passing in the change using the $my_meta_update variable.

    But the list item metabox seems to be a good bit more complex and I'm not sure how to go about updating/adding list items and populating the various sub fields using update_post_meta or add_post_meta.

    Anyone tackled this before or have some insight as to how to go about it? Any thoughts are much appreciated. Thank you!

    http://wordpress.org/extend/plugins/option-tree/

  2. htvu
    Member
    Posted 1 year ago #

    If you want to work with List Item manually, give a look at sanitize_callback function in ot-settings-api.php and save_meta_box function in ot-meta-box-api.php. Both php files located in includes folder of OT.

  3. Wee Beastie
    Member
    Posted 1 year ago #

    Thanks htvu, I appreciate your feedback here. Shortly after I started this thread, I enlisted the help of a buddy of mine and this is what we came up with. And by "we," I mostly mean "him."

    add_action( 'gform_after_submission', 'add_list_item', 10, 2 );
    function add_list_item( $entry, $form ){
        global $post;
    
        $list_meta = get_post_meta( $post->ID, 'list_metabox_id' );
    
        $new_list_item = $list_meta[0];
        $new_list_item [] = array(
            'title' => 'My Title',
            'sub_field_id_1' => 'Value 1',
            'sub_field_id_2' => 'Value 2',
            'sub_field_id_3' => 'Value 3'
        );
    
        delete_post_meta( $post->ID, 'list_metabox_id' );
        update_post_meta( $post->ID, 'list_metabox_id', $new_list_item );
    }

    I'm using a Gravity Form on the front end (hence the Gravity Forms hook shown above). When the form is submitted, it updates my list meta box with a new list item.

    Just posting this here in case anyone needs it. If you read this and think you have a better solution, by all means, post it for anyone who stumbles across this thread.

    Thanks again for taking the time to respond htvu.

  4. jvyda
    Member
    Posted 11 months ago #

    Hi Wee beastie,
    I am looking for a similar solution where i want to update a list item metabox values from the front end. Here is the option-tree metabox scructure

    $my_meta_box = array(
        'id'          => 'modules',
        'title'       => 'Modules',
        'desc'        => '',
        'pages'       => array( 'my-post-type' ),
        'context'     => 'normal',
        'priority'    => 'high',
        'fields'      => array(
    
          array(
            'id'          => 'insert_field',
            'label'       => 'Insert Field',
            'desc'        => '',
            'std'         => '',
            'type'        => 'list-item',
            'section'     => 'general',
            'rows'        => '',
            'post_type'   => '',
            'taxonomy'    => '',
            'class'       => '',
            'settings'    => array( 
    
              array(
                'id'          => 'module_thumb',
                'label'       => 'Module Thumbnail',
                'desc'        => '',
                'std'         => '',
                'type'        => 'upload',
                'rows'        => '',
                'post_type'   => '',
                'taxonomy'    => '',
                'class'       => ''
              ),
              array(
                'id'          => 'module_content',
                'label'       => 'Module Content',
                'desc'        => '',
                'std'         => '',
                'type'        => 'textarea',
                'rows'        => '',
                'post_type'   => '',
                'taxonomy'    => '',
                'class'       => ''
              )
            )
          )
    
      	)
      );

    Please if you can assist me on how to update these value from front end. It would be a great help. I assure you a free pass to the webapp i am building which requires this feature. cheers and thanks in advance

  5. esmi
    Forum Moderator
    Posted 11 months ago #

    As per the Forum Welcome, please post your own topic. This topic is 7 months old. Closing.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.