Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to add multiple featured image in meta box in post editor area apart from default available featured image.

I have added the meta box but i have no idea on adding the featured image functionality.

function another_image_custom_meta() {
    add_meta_box('another_meta', __('Another Image'), 'another_image_callback', 'another','side');
}

add_action('add_meta_boxes', 'another_image_custom_meta');

Where another in fourth field is my custom post type.

function another_image_callback($post) {
    wp_nonce_field(basename(__FILE__), 'another_nonce');
    $p_stored_meta = get_post_meta($post->ID);
    ?>

    <p>
       Another featured image
    </p>

    <?php
}

Above functions works fine it show the meta box.

How can i add the link with image upload and save it as featured image to the corresponding post. Like default featured image i want the same function here. can anyone help?

share|improve this question
    
You want any solution (i.e. plugin) or only info on how to implement it by yourself? –  Krzysiek Dróżdż Nov 13 '13 at 11:22
    
Hey check this wordpress.stackexchange.com/a/45864/42701 see if this helps you –  user42701 Nov 13 '13 at 11:22
    
No need any plugin.I already found multi post thumbnail does this.But i can't study the code there.so i want to Implement by myself so that i can learn each thing.If it is a easy learn guide that would be great. Thanks @ Krzysiek Dróżdż –  sun Nov 13 '13 at 11:25
    
Thanks. I'm looking for own implementation not any plugins @user42701 –  sun Nov 13 '13 at 11:28
    
I'm new to coding so i lack in understanding and reading code.That is why asking help here. Thanks @helgatheviking –  sun Nov 13 '13 at 12:09

1 Answer 1

I know you said you were looking for your own implementation, but the easiest way to add multiple featured image metaboxes is with the Multiple Post Thumbnail plugin.

Following the plugin's documentation, the way to define a secondary box is to add this code to your theme's functions.php

   if (class_exists('MultiPostThumbnails')) {
        new MultiPostThumbnails(
            array(
                'label' => 'Secondary Image',
                'id' => 'secondary-image',
                'post_type' => 'post'
            )
        );
    }

and then to display the image in your theme somewhere:

if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image'); endif;
share|improve this answer
    
Thanks for your time +1. I don't want to use another plugin.Need default WordPress way:) –  sun Nov 13 '13 at 12:29
3  
To learn how to do it yourself is one thing, but not using a plugin, just to "not use a plugin" is silly. There's nothing wrong with using plugins to simplify our lives. If by "the default WordPress way" you mean add and save metabox data, that is exactly what the plugin does. –  helgatheviking Nov 13 '13 at 12:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.