0
votes

In WordPress, when editing a post or a page, the Custom Field meta box allows the user to enter a name (meta_key) and a value (meta_value). I'm trying to modify the meta box so that the user can enter a:

a) name

b) value 1

c) value 2

My aim is to then use get_post_meta() to do something like this on the front-end of the site:

<a href="<?php echo $value1; ?>">
    <img src="<?php echo $value2; ?>" alt="" />
</a>

My question: How can I modify the Custom Fields meta box so that the user is able to enter 2 values next to each name?

So far, I've tried to use add_meta_box() but this adds a new box. My problem is I need to modify the existing box.

1

1 Answers

0
votes

Please see this code it may be help to overcome your problem..

add_action("admin_init", "my-function");
function my-function()
{
  add_meta_box("manage_option", "meta box name", "meta_box_value1", "post_type_name", "normal", "low");
  }

function meta_box_value1() 
{ 
 global $wpdb,$post;?>

 Enter text :<input type="text" id="sdate12"  name="text_val1" size="80" value="<?php echo      get_post_meta($post->ID,'meta_text_key',true); ?>" />
 <?php } 
add_action('publish_post_type_name', 'save_meta_value');
// to update text meta value  
function save_meta_value()
{
 global $wpdb,$post;    
 update_post_meta($post->ID, 'meta_text_key', $_POST["text_val1"]); 
 }