I have a function to get the date. I have input fields and want the date in this fields. But my code is set a wrong date. I set the date in Wordpress settings and on my server. But it is not working. This is my script:

function get_agenda_item_day() {
    global $post; 

        $cp_date = get_post_meta($post->ID, 'cp_date_end', true); 
        $cp_date_arr = explode("-",$cp_date);
        $day = $cp_date_arr[2];

    return $day;

And i use this in my select tag:

<?php $day = get_the_time('j'); ?> 
<select name="ad" id="ad" onChange="getNDay()" class="select select-n">
                    <option <?php if($day == 1) {echo 'selected="selected"';} ?> value="1">1</option>
                    <option <?php if($day == 2) {echo 'selected="selected"';} ?> value="2">2</option>
                    <option <?php if($day == 3) {echo 'selected="selected"';} ?> value="3">3</option>
                    <option <?php if($day == 4) {echo 'selected="selected"';} ?> value="4">4</option>
etc etc etc

But, what do i wrong. Always the date is 17 juni in the select box. Because today the date is 5 Juli.

Thanks for help

1 Answer 1


You have to pass the second parameter $post to get_the_time('j'):

get_the_time( 'j', $post );

If you don’t WordPress will just use whatever the current global post object is.

  • This is not working. It results in 17 juni. Because it is not 17 juni Commented Jul 5, 2012 at 20:37
  • 1
    Did you actually try what toscho suggested? Please be aware that get_the_time() returns the time a certain post was posted. If you don't specify a post it will return the post time for the current post out of the main loop (global $post). If it returns "17. june" it means that the current post was posted at that time!
    – s1lv3r
    Commented Feb 25, 2013 at 14:41
  • I interpret your question as you wanting to extract a date from post meta. If this is the case, then you need to store it in post meta first. The best would be to update your description with more details and some more code.
    – Fränk
    Commented Apr 30, 2013 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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