0

I have some custom fields added via a meta box, and I'd like to output them into a dl on the post itself, with the field being the term and the data it contains being the term. Currently, calling <?php the_meta(); ?> outputs an unordered list.

Example:

<dl>
  <dt>Date</dt><dd>Monday 26 March 2012</dd>
  <dt>Time</dt><dd>11pm</dd>
</dl>

I have the meta box fully implemented, it's just the output that I'm clueless with. The relevant part of the meta box code, should it help:

function admin_init(){
  add_meta_box("events_meta", "Event Details", "event_details", "post", "normal", "default");
}

function event_details() {
  global $post;
  $custom = get_post_custom($post->ID);
  $date = $custom["date"][0];
  $time = $custom["time"][0];
  $location = $custom["location"][0];
  $tickets = $custom["tickets"][0];
  ?>
  <p><label>Date:</label><br />
  <textarea cols="34" rows="2" name="date"><?php echo $date; ?></textarea></p>
  <p><label>Time:</label><br />
  <textarea cols="34" rows="2" name="time"><?php echo $time; ?></textarea></p>
  <p><label>Location:</label><br />
  <textarea cols="34" rows="2" name="location"><?php echo $location; ?></textarea></p>
  <p><label>Ticket Price(s):</label><br />
  <textarea cols="34" rows="2" name="tickets"><?php echo $tickets; ?></textarea></p>
  <?php
}

Thanks in advance for any help! :)

0

You can use get_post_meta() function to retrieve values of fields.

Example :

To retrieve the value of date metabox use following code.

get_post_meta(get_the_ID(), 'date', true);
  • That worked perfectly in conjunction with an echo <?php if ( get_post_meta($post->ID, 'date', true) ) : ?> <dt id="date-icon">Date</dt> <dd><?php echo get_post_meta($post->ID, 'date', true) ?></dd> <?php endif; ?> Thanks! :) – TheGuest Mar 27 '12 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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