How to clone posts / populate form based on other posts

Support MB Frontend Submission How to clone posts / populate form based on other posts

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35321
    Sam UnderwoodSam Underwood
    Participant

    I need a way for the users to create a new post based on other posts.
    So, everything would start the same (except for the ID, obviously)
    I believe I have to be able to populate the frontend form, but I'm not sure how.

    #35332
    Long NguyenLong Nguyen
    Moderator

    Hi Sam,

    MB Frontend Submission does not support duplicating a post based on another one. In the backend, you can try to use a third-party plugin https://wordpress.org/plugins/duplicate-post/

    #35363
    Sam UnderwoodSam Underwood
    Participant

    That wouldn't work for this case.

    I have a code that's almost working. It's able to clone every field except for groups.

    Here's how it's looking like so far:

    // duplicate all post meta
    $post_meta = get_post_meta( $post_id );
    if( $post_meta ) {
    	foreach ( $post_meta as $meta_key => $meta_values ) {
    		foreach ( $meta_values as $meta_value ) {
    			add_post_meta( $new_post_id, $meta_key, $meta_value );
    		}
    	}
    }

    How could I improve this so it'll also be able to go through the subfields?

    #35382
    Sam UnderwoodSam Underwood
    Participant

    Rephrasing it:
    How do I use get_post_meta and add_post_meta with group subfields?

    #35384
    Long NguyenLong Nguyen
    Moderator

    Hi Sam,

    The group field saves the subfield values under the meta key group_id in the database. So if you want to duplicate a group field, please use its ID to update the value. Refer to this documentation
    https://docs.metabox.io/extensions/meta-box-group/#getting-sub-field-values

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