Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134332

M. Nisp. on "Convert Date Format in Meta Box"

$
0
0

Hello WordPressers,

I'm building a upcoming events custom posttype with a meta box in which I can manage on which dates a post is displayed en when not. (I want to learn WordPress, so I do not want to use a Plugin.)

With the meta box I want to accomplish these 3 things:
(i) enter date in d,m,Y format. (ii) Store this date in Y,m,d format and show it in (iii) d,m,Y format again.

I have made a variable for each step. My problem is that I can't get the date that is filled in in the meta box, stored as described in (ii), hence (iii) is failing to. I am quite new to WordPress so I also have problems deciding what to do where: which step(s) do I have to put in the callbackfunction and which in the savefunction.

The code:

<?php
    function show_events_meta($post)
    {

    // - grab data -
        $startDate = get_post_meta($post->ID, 'Startdate', true);

        if(empty($startDate)) {
            $startDate = date('Y-m-d');
        }

    $readableStartDate = date("d-m-Y", strtotime($startDate));
    $humanDate = date ('d-m-Y', strotime ($readableStartdate);
    $computerDate = date('Y-m-d', strtotime($humanDate));
    $newHumanDate = date('d-m-Y', strtotime($computerDate));

 <div class="datemeta">

<ul>
<li><label>Start Date</label><input name=Startdate id=Startdate class="stdate"
                                                value="<?php echo $readableStartDate; ?>"/></li>
</ul>
    </div>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Kind regards,


Viewing all articles
Browse latest Browse all 134332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>