• Resolved Peter Berger

    (@peterpolow)


    Hello Eliot, I think setting the date-format for an acf date field, does not work.

    I have read the topic “Show content by date-field” and I got it also work with te acf “date and time picker field” plugin (in the settings of the field, set “safe as timestamp?” and “Get field as timestamp” to “No”).

    My code is like this:
    [loop type=”announcement” acf_date=”expires” value=”future” orderby=”field_num” order=”DESC”]
    [content]
    [field acf_date=”expires”]
    [/loop]

    It was hard to get this work. I set the date-format in the field options to “d MM yy” and the time-format to “HH:mm” and didn’t set the date-format as a parameter in the loop shortcode. (My date- and time-format in the general WordPress settings is “j F Y H:i”).

    If I don’t set the date_format parameter in the field shortcode, the output for “expires” is “30 februari 2015 22:00”. When I set a date-format (for example “d-m-Y H:m” or “j F Y H:i” (or without the time), not the value of the field will display, but the actual date (and time) in the given format.

    I also tried it with the “default” acf date field, but it doesn’t work either.

    An other problem: if I use the \\ (double backslashes) before a character in de date_format parameter, the characters will not show.

    I hope you can help me with this problem. It don’t have a high priority, so take your time! ??

    Thank you in advance!

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Thanks for pointing this out. As you see from the other thread, the handling of date format has room for improvement – especially because ACF allows a variety of ways to get and save date fields.

    About escaping with backslashes – I found that backslashes inside shortcode parameters are not getting passed. This happens before it gets to the shortcode function, so I added a workaround in the latest plugin update. Now, you should be able to escape with double slashes.

    I installed ACF date & time picker. It seems to work best if the field is saved as timestamp. It’s a bit confusing for me also – ACF date picker saves its fields as “Ymd” (20150217), and the acf_date parameter for [loop] is expecting this format. However this doesn’t work for the date & time picker. After some experimentation, what worked for me is:

    1) Save date & time field as timestamp
    2) To get future dates with loop, use the field parameter

    [loop type="post" count="10" field="acf_date_time" value="future"]

    3) To format the field, use in=”timestamp”. Also double slashes to escape.

    [field acf_date_time in="timestamp" date_format="Y/m/d //a//t g:i A"]

    I’ll note this in the documentation. It still feels like this could be improved/simplified somehow.

    Thread Starter Peter Berger

    (@peterpolow)

    You are good, Eliot! I wish I had your brains! ??
    Thank you for your time to figuring this out.

    For some reason, when using some date-formats in the field options, the field is empty after saving the post (if “Save as timestamp” is set to “Yes” in the field options).

    What works for me (maybe it could help others) is date-format dd/mm/yy and time-format HH:mm. A date-format without the slashes didn’t work for me.

    My code is now like this:

    [loop type="announcement" field="expires" value="future" orderby="field_num" order="ASC"]
    [content]
    Expires: [field expires in="timestamp" date_format="l j F Y //o//m H:i"]
    [if empty]No announcements.[/if]
    [/loop]

    Sorting the posts, formatting the date & time and // before a character now works perfect! ??

    Thanks again!

    Thread Starter Peter Berger

    (@peterpolow)

    Just a short question:

    The date/time field now compares with the current UTC time, but my local time is one hour later. The timezone in my general Worpress settings is also set to an hour later (Amsterdam) and so is the time of my computer (I’m using WAMP).

    Is there an option to compare the date/time field with the time of my WordPress installation (or local server)?

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Setting date-format for acf date field outputs actual date (and \\ doesn't work)’ is closed to new replies.