Metabox zeigt kein Video an

Ich versuche eine Metabox hinzuzufügen, um ein Video auszuwählen. Aber aus bestimmten Gründen sehe ich immer wieder, dass die angehängte URL leer ist. Daher wird das Video natürlich nicht angezeigt. Hier ist der Code:

ID, '_wp_page_template', true ) ) { add_meta_box( 'prfx_meta', __( 'Vidéo Présentation Bas de Page', 'prfx-textdomain' ), 'prfx_meta_callback', 'page' ); } } add_action( 'add_meta_boxes', 'prfx_custom_meta' ); /** * Outputs the content of the meta box */ function prfx_meta_callback( $post ) { wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stored_meta = get_post_meta( $post->ID ); ?> 

<input type="text" name="meta-text" id="meta-text" value="" />

<input type="text" name="meta-url" id="meta-url" value="" />

<input type="text" name="meta-image" id="meta-image" value="" /> <input type="button" id="meta-image-button" class="button" value="" />

<img src="https://wordpress.stackexchange.com/questions/267466/metabox-does-not-display-video/" style="max-width: 250px;">

<input type="text" name="meta-video" id="meta-video" value="" /> <input type="button" id="meta-video-button" class="button" value="" />

__( 'Choose or Upload an Image', 'prfx-textdomain' ), 'button' => __( 'Use this image', 'prfx-textdomain' ), ) ); wp_enqueue_script( 'meta-box-image'); } } add_action( 'admin_enqueue_scripts', 'prfx_image_enqueue' ); /** * Loads the video management javascript */ function prfx_video_enqueue() { global $typenow; if( $typenow == 'page' ) { wp_enqueue_media(); // Registers and enqueues the required javascript. wp_register_script( 'meta-box-video', get_template_directory_uri() . '/inc/meta-box-video.js', array( 'jquery' ) ); wp_localize_script( 'meta-box-video', 'meta_image', array( 'title' => __( 'Choose or Upload an Image', 'prfx-textdomain' ), 'button' => __( 'Use this image', 'prfx-textdomain' ), ) ); wp_enqueue_script( 'meta-box-video'); } } add_action( 'admin_enqueue_scripts', 'prfx_video_enqueue' );

Und das Script js

 /* * Attaches the image uploader to the input field */ jQuery(document).ready(function($){ // Instantiates the variable that holds the media library frame. var meta_image_frame; // Runs when the image button is clicked. $('#meta-video-button').click(function(e){ // Prevents the default action from occuring. e.preventDefault(); // If the frame already exists, re-open it. if ( meta_image_frame ) { meta_image_frame.open(); return; } // Sets up the media library frame meta_image_frame = wp.media.frames.meta_image_frame = wp.media({ title: meta_image.title, button: { text: meta_image.button }, library: { type: 'video' } }); // Runs when an image is selected. meta_image_frame.on('select', function(){ // Grabs the attachment selection and creates a JSON representation of the model. var media_attachment = meta_image_frame.state().get('selection').first().toJSON(); // Sends the attachment URL to our custom image input field. $('#meta-video').val(media_attachment.url); }); // Opens the media library frame. meta_image_frame.open(); }); }); 

Alle anderen Meta-Boxen funktionieren, nur dieses Video “Meta-Video”, das einen leeren Link gibt.

Ich danke dir sehr für deine Hilfe!

Solutions Collecting From Web of "Metabox zeigt kein Video an"