• inula

    (@janetb)


    Hi there,

    I found the solution for my question, but I don’t understand.
    I have a custom field tweede_voorstelling. It’s a date/time field.I would like to change the format.
    I refer to this field in my catlist-command like this:
    [catlist name=”actueel” template=imgtit customfield_display=”tweede_voorstelling”]

    I do have a custom template: imgtit.
    I added the two lines (see below). But then what?
    I don’t understand:Now you can use the dateTime object to output your date wherever you want, in whatever format you want. Just call $dateTime->format(‘l jS F Y’)

    Here the answer of the author I found:

    First create a custom template.

    In the template file, use this code:

    $date = get_post_meta( $post->ID, ‘[your custom field name]’, true );
    $dateTime = DateTime::createFromFormat(“Y-m-d”, $date);

    Remember to replace [your custom field name] with an actual custom field name.

    Now you can use the dateTime object to output your date wherever you want, in whatever format you want. Just call $dateTime->format(‘l jS F Y’);

    Hope it helps.

    • This topic was modified 6 years ago by inula.
    • This topic was modified 6 years ago by inula.
Viewing 2 replies - 1 through 2 (of 2 total)
  • redweatherday

    (@redweatherday)

    Hi inula, I had a similar problem.

    I posted it on github and the author kindly provided help:

    https://github.com/picandocodigo/List-Category-Posts/issues/365

    This is part of my modified template:

    $date = get_post_meta( $post->ID, ‘walk_date’, true );
    $dateTime = DateTime::createFromFormat(“Ymd”, $date);

    //Start a List Item for each post:
    $lcp_display_output .= “

    • “;

      //Show the title and link to the post:
      $lcp_display_output .= $this->get_post_title($post, ‘h3’, ‘lcp_post’);

      //Show comments:
      $lcp_display_output .= $this->get_comments($post);

      //Show date:
      $lcp_display_output .= ‘ ‘ . $this->get_date($post);

      //Show date modified:
      $lcp_display_output .= ‘ ‘ . $this->get_modified_date($post);

      //Show author
      $lcp_display_output .= $this->get_author($post);

      //Custom fields:
      $lcp_display_output .= ““;
      $lcp_display_output .= $dateTime->format(‘l, jS F Y’);
      $lcp_display_output .= $this->get_custom_fields($post);
      $lcp_display_output .= “
      “;
      $lcp_display_output .= “<div class=walk_note_red>”;
      $lcp_display_output .= get_field(‘walk_note’);
      $lcp_display_output .= “</div>”;

      Hope this helps.

    Thread Starter inula

    (@janetb)

    Ahhh, thanks @redweatherday,

    That really heldped!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘date format of custom field’ is closed to new replies.