Ich habe ein Post-Meta zum Hochladen von Bildern mit WordPress Media Uploader hinzugefügt. Sieht aus wie es eine Javascriptarbeit ist. Ich bin nicht gut in Javascript. Ich habe die js von hier genommen:
Hier ist der js-Code:
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-image-button').click(function(e){
// Prevents the default action from occuring.
e.preventDefault();
// If the frame already exists, re-open it.
if ( meta_image_frame ) {
wp.media.editor.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: 'image' }
});
// 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-image').val(media_attachment.url);
});
// Opens the media library frame.
wp.media.editor.open();
});
});
Ich habe ein Eingabefeld mit der ID #meta-image
. Die img-URL wird dort jedoch nicht zurückgegeben. Stattdessen wird die Bild-URL im Haupt-Post-Editor abgelegt. Irgendeine Idee, wie ich das zum Laufen bringen kann?
Ich habe dieses Problem gelöst, indem ich wp.media.editor.open()
in meta_image_frame.open()
geändert habe.
Es funktioniert jetzt gut. Ich bin mir aber nicht sicher, was der Fehler vorher war.