• Resolved rob_870

    (@rob_870)


    Hi

    I’m using this code to display custom meta on my site below but want to change the format of the date to show (‘l, F jS, Y’).

    I have very little PHP knowledge and don’t know where I should put it?

    <div class=”meta”><b>Race Date:</b> <?php $key=”event_date”); echo get_post_meta($post->ID, $key, true );?></div>

    Thanks in advance
    Rob

Viewing 3 replies - 1 through 3 (of 3 total)
  • Rob, What exactly does this hold:
    get_post_meta($post->ID, $key, true );

    From there we can format it.

    One “cheat” function of wordpress is strtotime.

    try this:

    <div class="meta">
    	<b>Race Date:</b>
    	<?php
    	$meta = get_post_meta($post->ID, 'event_date', true );
    	esc_html_e( date( 'l, F jS, Y' , strtotime( $meta ) ) );
    	?>
    </div>

    This is collecting the post meta, escaping any nasties that could be contained in it and formatting the date correctly. Untested, but should work.

    Thread Starter rob_870

    (@rob_870)

    That’s brilliant, thanks so much! You are a legend!

    rob

    strtotime is not a wordpress function, it is a PHP function. Sorry for any confusion.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Simple change to date format help on custom meta field’ is closed to new replies.