• I have a metabox as follows –

    array(
           'id'   => 'released',
           'name' => __( 'Release Date', 'textdomain' ),
           'type' => 'date',
       ),

    Which outputs the date in the format of Y-m-d even though I have the date format set as d-m-Y in admin ui. I output as follows –

    <?php $rel = get_post_meta( get_the_ID(), "released", true ); ?>
    <?php echo $rel; ?>

    My 2 questions are –
    How would I output the date format as d-m-Y
    And how would I WP_Query to just list the posts of a designated year like 1980.

    Thanks in advance
    Steven

    [Moderator note: this is a duplicate of https://www.ads-software.com/support/topic/meta-box-date-format/. Please continue there.]

Viewing 1 replies (of 1 total)
  • Maybe something like this?

    $rel = get_post_meta( get_the_ID(), "released", true );
    $date = new DateTime($rel);
    echo $date->format('d-m-Y');

    I’m not sure how you could query just the year from this though, if the year was kept in a separate meta box then this would be possible using WP_Meta_Query.

    Hope this helps.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_Query date format’ is closed to new replies.