Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
</select>

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

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
This is not working. It results in 17 juni. Because it is not 17 juni –  Mike Vierwind Jul 5 '12 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 Feb 25 '13 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 Apr 30 '13 at 20:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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