Support » Plugin: Meta Box - WordPress Custom Fields Framework » Set Images in Image Advanced Metabox

  • Resolved Sameer

    (@sameernxb)


    Hi,

    I am using the plugin for generating metaboxes. I have several radio buttons and several other fields. I am getting user data and using wp_insert_post which is a WordPress function i am adding that data in custom fields of Metabox plugin. Can you tell me how i can use the same function for setting gallery images attachment id in the Image Advanced metabox using the wp_insert_post function. I am getting gallery images id but i want them to be set in Image Advanced metabox using the wp_insert_post function or via any custom code and in this regard i need help. Is there any workaround for that where i can give attachment ID of gallery images to the Image Advanced metabox and the metabox can set the images with preview automatically. Is there any way or hook or filter which can help me. Looking forward to your response.

    Best Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi Sameer,

    The image_advanced field stores image IDs in multiple rows in the post meta. So you just need to do this after you insert post (so you know the post ID):

    foreach ( $image_ids as $image_id ) {
        add_post_meta( $post_id, 'field_id', $image_id, false );
    }

    Notice the last parameter, it has to be “false”.

    Hi Tran,

    Thanks i figured this out. There is one more thing i have some text which i want to store in the input repeatable fields. This is basically some achievement content which i want to save in the repeatable input fields of Metabox plugin. Can you tell me how i can achieve that. Is there any hook or filter for that. I am getting all the posts just i want to store them via code in the input repeatable fields of Metabox plugin. Any help is greatly appreciated. Looking forward to your response.

    I think this is how it is storing in the database. a:1:{i:0;s:4:”test”;}

    Thanks,
    Sameer

    • This reply was modified 8 months, 1 week ago by Sameer.
    Plugin Author Anh Tran

    (@rilwis)

    Hi Sameer,

    The repeatable field (or clonable field in Meta Box) stores values as an serialized array in the database. So, to store the values, simply do this:

    $values = array( 'value 1', value 2' );
    add_post_meta( $post_id, 'field_id', $values );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set Images in Image Advanced Metabox’ is closed to new replies.