Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong></p> <p>Okay first of all, you can not <strong>upload</strong> a file from any of the metaboxes. Reason? Well, because WordPress wraps all of the post stuff inside a <code>&lt;form&gt;</code> which does not have the necessary attributes to upload files.</p> <p>So the solution is to provide an option to upload using WordPress default media uploader and save the URL instead.</p> <p>Here is a working example. Please use this as a guide, not as your production code. In reality you'd like to fine tune the media uploader button so that multiple button can add multiple urls to multiple inputs.</p> <p>http://example.com/wordpress-plugins/my-plugin Description: A plugin demonstrating Cron in WordPress Version: 1.0 Author: Brad Williams Author URI: <a href="http://wrox.com" rel="nofollow">http://wrox.com</a> License: GPLv2 */</p> <pre><code>add_action( 'init', 'register_tagging_post' ); function register_tagging_post() { $tagging_args = array( 'public' =&gt; true, 'supports' =&gt; array( 'title', 'thumbnail' ), 'query_var' =&gt; 'tagging', 'rewrite' =&gt; array( 'slug' =&gt; 'tagging', 'with_front' =&gt; false ), 'labels' =&gt; array( 'name' =&gt; 'Albums', 'singular_name' =&gt; 'Album', 'add_new' =&gt; 'Add New Album', 'add_new_item' =&gt; 'Add New Album', 'edit_item' =&gt; 'Edit Album', 'new_item' =&gt; 'New Album', 'view_item' =&gt; 'View Album', 'search_items' =&gt; 'Search Albums', 'not_found' =&gt; 'No Albums Found', 'not_found_in_trash' =&gt; 'No Albums Found In Trash' ), ); register_post_type( 'tagging', $tagging_args ); } //add metabox add_action( 'add_meta_boxes', 'boj_mbe_create' ); function boj_mbe_create() { //create a custom meta box add_meta_box( 'boj-meta', 'My Custom Meta Box', 'boj_mbe_function', 'tagging', 'normal', 'high' ); } function boj_mbe_function( $post ) { $file_meta_data = get_post_meta( $post-&gt;ID, 'taggr_file', true ); ?&gt; &lt;input type="text" class="regular-text" name="taggr_file" id="taggr_file" value="&lt;?php echo $file_meta_data; ?&gt;" /&gt; &lt;button id="taggr_upload" class="button-primary"&gt;Upload&lt;/button&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function($) { // Uploading files var file_frame; jQuery('#taggr_upload').on('click', function( event ) { event.preventDefault(); // If the media frame already exists, reopen it. if ( file_frame ) { file_frame.open(); return; } // Create the media frame. file_frame = wp.media.frames.file_frame = wp.media({ title: jQuery( this ).data( 'uploader_title' ), button: { text: jQuery( this ).data( 'uploader_button_text' ), }, multiple: false // Set to true to allow multiple files to be selected }); // When an image is selected, run a callback. file_frame.on( 'select', function() { // We set multiple to false so only get one image from the uploader var attachment = file_frame.state().get('selection').first().toJSON(); // Do something with attachment.id and/or attachment.url here $('#taggr_file').val(attachment.url); }); // Finally, open the modal file_frame.open(); }); }); &lt;/script&gt; &lt;?php } //hook to save the meta box data add_action( 'save_post', 'boj_mbe_save_meta' ); function boj_mbe_save_meta( $post_id ) { //verify the meta data is set if ( isset( $_POST['taggr_file'] ) ) { update_post_meta( $post_id, 'taggr_file', stripslashes( $_POST['taggr_file'] ) ); } } </code></pre> <p>If you're still facing any problem, then feel free to reply :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload