I am trying to display image from my custom meta box but cant make it:
function.php file:
add_action( 'admin_init', 'order_box' );
function order_box() {
add_meta_box( 'meta-box-id', 'My Custom Field', 'my_custom_field', 'post', 'normal', 'high' );
}
function my_custom_field(){
global $post;
$custom = get_post_custom($post->ID);
$order=$custom["order"][0];
$image=$custom["image"][0];
?>
<label for="custom_field">Put Order:</label>
<input type="text" name="order" value="<?php echo $order; ?>" />
<label for="custom_field">Upload Image:</label>
<input type="file" name="image" />
<?php
}
add_action('save_post', 'save_order');
function save_order(){
global $post;
update_post_meta($post->ID, "order", $_POST["order"]);
update_post_meta($post->ID, "image", $_POST["image"] );
}
my template file where i want display the image:
<?php
while (have_posts()) : the_post(); ?>
<h1><a href="https://wordpress.stackexchange.com/questions/75550/<?php the_permalink();?>"> <?php the_title(); ?></a> </h1>
<?php the_content(); ?>
<?php
$custom = get_post_custom($post->ID);
$image=$custom["image"][0];
$order=$custom["order"][0];
echo $order;
?>
//*** <img src="<?php echo $image; ?>" />
<img src="<?php echo get_post_meta($post->ID,'image',true); ?>"
width=200 height=200 />
endwhile;
here ‘order’ is displayed nicely but not image. print_r($custom) got something like this:
Array (
[_edit_last] => Array ( [0] => 1 )
[order] => Array ( [0] => 13 )
[image] => Array ( [0] => coffee_star.jpg )
)
someone please help me to display the image in my template page. I am very new to wordpress. Thanks in advance.