Site icon Hip-Hop Website Design and Development

How can I create a customized meta field so as to add an mp4 video to a web page?

I’ve cobbled collectively code (as I am a php and jquery beginner) from a few totally different posts to attempt to get an mp4 video URL enter area within the wordpress admin. I have been capable of get a media uploader to show, select a file and on choose populate a kind area with the URL within the wordpress admin nevertheless after I click on replace the URL disappears. I can not for the lifetime of me determine what I must do to show this URL as soon as the web page is up to date. Any assist can be vastly appreciated! Right here is the code that I’ve added to my features.php (please disregard that the id and many others is known as “add picture” versus video I will change all of that after I get it working):

    add_action('plugins_loaded', perform(){ 
    if($GLOBALS['pagenow']=='publish.php'){
    add_action('admin_print_scripts', 'my_admin_scripts');
    add_action('admin_print_styles',  'my_admin_styles');
}
});

perform my_admin_scripts() { wp_enqueue_script('jquery');    wp_enqueue_script('media-upload');   wp_enqueue_script('thickbox'); }   
perform my_admin_styles()  { wp_enqueue_style('thickbox'); }

    add_action('add_meta_boxes', perform(){  add_meta_box('my-metaboxx1', 'my-metaboxx1-title','func99999', get_post_types(),'regular'); }, 9);

perform func99999($publish){ 
$attachment =get_post_meta($post->ID,'my-image-for-post', true);   ?>

Right here is the HTML for the shape area:

<label for="upload_image">
<enter id="upload_image" sort="textual content" measurement="36" identify="ad_image" worth="<?php echo $attachment; ?>" /> 
<enter id="upload_image_button" class="button" sort="button" worth="Add Picture" />
<br />Enter a URL or add a picture
</label>

Right here is the jQuery:

<script>
    jQuery(doc).prepared(perform($){


var custom_uploader;


$('#upload_image_button').click on(perform(e) {

    e.preventDefault();

    //If the uploader object has already been created, reopen the dialog
    if (custom_uploader) {
        custom_uploader.open();
        return;
    }

    //Prolong the wp.media object
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Select Picture',
        button: {
            textual content: 'Select Picture'
        },
        a number of: false
    });

    //When a file is chosen, seize the URL and set it because the textual content area's worth
    custom_uploader.on('choose', perform() {
        attachment = custom_uploader.state().get('choice').first().toJSON();
        $('#upload_image').val(attachment.url);
        $('#upload_image').attr("src", attachment.url);
    });

    //Open the uploader dialog
    custom_uploader.open();

});


});
</script>

Here’s what I am utilizing to attempt to save the enter area:

add_action( 'save_post', perform ($post_id) {
if (isset($_POST['upload_image'])){
    update_post_meta($post_id, 'my-image-for-post',$_POST['upload_image']);
}
});

Is is feasible that I want to vary the worth on this line or is there a bigger situation?

<enter id="upload_image" sort="textual content" measurement="36" identify="ad_image" worth="<?php echo $attachment; ?>" />