How to save post meta data

I´m trying to save the images after I select in the wordpress image manager.

I can select images and with jquery fill the urls and insert name = ‘my_image_URL’ into the input of each selected image:

$("#show").after("<input class='upload_image' type='text' size='36' name='my_image_URL' value= " +attachment.url+ " /></br><img src=" +attachment.url+" class='my_image' src='' width='80px'></br>");

The meta box is working OK, but when I save the post, it does not save the images in wp_postmeta table, I tried the two forms below:

1

add_action( 'save_post', function ($post_id) {

    if (isset($_POST['my_image_URL'])){
            $urls = $_POST['my_image_URL'];

            Foreach ($urls as $url){
        $key1_values = get_post_custom_values( 'my-image-for-post', $post_id );
        Foreach($key1_values as $value){
            update_post_meta($post_id, 'my-image-for-post', $url, $value);
        }
        }
   }

});

2

add_action( 'save_post', function ($post_id) {

        if (isset($_POST['my_image_URL'])){
        $urls = $_POST['my_image_URL'];

         Foreach ($urls as $url){
            update_post_meta($post_id, 'my-image-for-post',$url);
        }
    }

});

But it does not save the urls of the postmeta, what can I be doing wrong?

Thanks for your help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.