Displaying meta data
-
Hello
I am wanting to display meta data on my WP site…
I am using a write panel that I have started using a great tutorial I found… my functions file has the following code:
/* Plugin Name: Custom Write Panel Plugin URI: https://wefunction.com/2008/10/tutorial-create-custom-write-panels-in-wordpress Description: Allows custom fields to be added to the WordPress Post Page Version: 1.0 Author: Spencer Author URI: https://wefunction.com /* ----------------------------------------------*/ $new_meta_boxes = array( "image" => array( "name" => "image", "std" => "", "title" => "Product Image", "description" => "Enter full path to image here." ), "price" => array( "name" => "price", "std" => "", "title" => "Product Price", "description" => "Only numbers and periods! DO NOT ENTER \"$\"!" ), "size" => array( "name" => "sizes", "std" => "", "title" => "Available Sizes", "description" => "Enter comma-separated values. (ex: \"Small, Medium, Large\")" ), "colors" => array( "name" => "colors", "std" => "", "title" => "Available Colors", "description" => "Enter comma-separated values. (ex: \"Red, White, Blue\")" ), "catalog" => array( "name" => "catalog", "std" => "", "title" => "Catalog Number", "description" => "Enter catalog number here." ), "cannotbuy" => array( "name" => "cannotbuy", "std" => "", "title" => "Cannot Purchase Online", "description" => "If this is an item that is not allowed to be sold online, type in \"yes\" or \"y\"." ), "sale" => array( "name" => "sale", "std" => "", "title" => "Sale Price", "description" => "Enter in a dollar amount or percentage off - be sure to include the \"$\" or \"%\" symbols." ), "quantity" => array( "name" => "quantity", "std" => "", "title" => "Quantity in Stock", "description" => "Enter in a value for how many items you have in stock." ) ); function new_meta_boxes() { global $post, $new_meta_boxes; foreach($new_meta_boxes as $meta_box) { $meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true); if($meta_box_value == "") $meta_box_value = $meta_box['std']; echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />'; echo'<h2>'.$meta_box['title'].'</h2>'; echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" size="55" /><br />'; echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>'; } } function create_meta_box() { global $theme_name; if ( function_exists('add_meta_box') ) { add_meta_box( 'new-meta-boxes', 'Course Information', 'new_meta_boxes', 'post', 'normal', 'high' ); } } function save_postdata( $post_id ) { global $post, $new_meta_boxes; foreach($new_meta_boxes as $meta_box) { // Verify if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) { return $post_id; } if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id )) return $post_id; } $data = $_POST[$meta_box['name'].'_value']; if(get_post_meta($post_id, $meta_box['name'].'_value') == "") add_post_meta($post_id, $meta_box['name'].'_value', $data, true); elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true)) update_post_meta($post_id, $meta_box['name'].'_value', $data); elseif($data == "") delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true)); } } add_action('admin_menu', 'create_meta_box'); add_action('save_post', 'save_postdata'); ?>
My problem is that the meta – displayed using : <?php the_meta(); ?> in single.php displays the data thusly:
price_value: 4
Where I want it to read
Price: 4
As seen on the site im making: here
Any help appreciated!
Dave
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Displaying meta data’ is closed to new replies.