Viewing 4 replies - 1 through 4 (of 4 total)
  • Custom fields work as name value pairs.

    In the custom fields section under “name” input “exp_date”(or something) and under the “value” put “May 13th, 2010″(or diff format).

    To retrieve in template file:

    <?php
    // get the custom field value by this function
    $expDate = get_post_meta($post->ID, 'exp_date', $single = true);
    // if there is a value input for exp_date
    if($expDate !== '') {
    ?>
    // Do something here like echo $expDate;
    <?php } ?>

    The option to select “exp_date” will now be for each post and wp will remember which value is assigned for each post. If you put nothing, the code will be skipped.

    Just a word of caution with how you “structure” the date in your custom field–if you are going to use query_posts to return a sorted list of posts by that custom field you would want to use a date that would be like “2010-04-24”.

    Thread Starter giankar

    (@giankar)

    Where should I add this code?

    Put that in The Loop which is typically a structure that begins with

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    and ends with an

    endwhile and endif or }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Question about custom field’ is closed to new replies.