Support » Plugin: Custom Content Type Manager » datepicker regional (2)

  • Resolved bluantinoo

    (@bluantinoo)


    Hi,
    I was trying to figure out how to use a regional datepicker and (obviously) regional date format, when I found this topic:
    http://wordpress.org/support/topic/plugin-custom-content-type-manager-datepicker-regional?replies=6

    I would continue the discussion there, but the topic is closed…

    I’m wondering if any progress has been done on that issue. My website is in Italian Language and I need a totally different date formatting why the only options to format date on CCTM are in english language.

    I would need to format date like this: ‘d/m/Y’

    The only way I was able to do it is to:
    1) set on CCTM custom date field the MySQL format ‘yyyy-mm-dd’
    2) apply function ‘mysql2date(‘d/m/Y’, $mydate )’

    but this is evidently a workaround, datepicker in backend remains in english and the date format ‘yyyy-mm-dd’ in input field is difficult to read for an italian admin.

    Would not be easier to leave empty the “date format options” of CCTM so I can write down my own formatting without be forced to choose from one of the options? Or just adding a “free-formatting” field just like WP general options?

    http://wordpress.org/plugins/custom-content-type-manager/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    There are 2 very different conversations here: one is how you STORE the date, and for that I always recommend using the MySQL format since you can sort it correctly. This isn’t “English” or any other locale: it’s just a computer format that works for sorting and retrieving dates. In my opinion, it’s usually a bad idea to store dates in a human-readable formats because you will have trouble sorting them and the inputs can be inconsistent. This isn’t anything to do with the CCTM, it’s just “common sense” when it comes to databases and programming.

    The second area where date formatting comes into play is when you DISPLAY the data on the front-end in your theme. That format can be whatever format you want: you can use PHP’s date() function to format the date or you can use the CCTM’s helper datef filter: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/datef_OutputFilter If you use the CCTM’s datef filter, it will default to your blog’s “date_format” setting.

    Hope that makes sense.

    Thread Starter bluantinoo

    (@bluantinoo)

    Hi fireproofsocks,
    thanks for answering.

    Actually I was thinking that the date was stored just in mysql format, no matter what date formatting I choosed.

    So, if I understand, the “Date format” option (I post a screenshot to be sure we are talking about the same thing: http://prntscr.com/1p4xpd) it’s the db storing format?

    If yes, how to make the date written in back-end datepicker field to have the the same format of front end?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Correct: that screenshot is showing the format used when storing the values in the database. The output filter would control the visible options when the values are printed in the themes.

    Thread Starter bluantinoo

    (@bluantinoo)

    The output filter would control the visible options when the values are printed in the themes.

    This is valid also in backend, on datepicker input fields?

    if yes it’s not working. Or I’m not able to.
    this is my Output filter setting: http://prntscr.com/1p54u5
    and this is my datepicker input field: http://prntscr.com/1p552c

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    I’m not sure what you’re asking re “valid in backend”.

    The datef filter would require some options set in your theme file. You can pass options to it as you wish as demonstrated in the examples:

    print get_custom_field('my_date:datef', 'F j, Y, g:i a');

    You need to be specific when you say “It’s not working.” You need to specify what you expected to see vs. what you actually saw.

    A lot of people get confused by the output filters: if you select a DEFAULT output filter (like you did in your screenshot), it means that the filter will be used IF you haven’t selected any other filter and it will use the DEFAULT options. The default output filter is completely unnecessary — it just saves you from having to verbosely type out the output filter in your theme files.

    Thread Starter bluantinoo

    (@bluantinoo)

    fireproof, thanks for your patience.
    What I would like to do is just sync the way the date looks both in theme files and in backend datepicker input fields.

    In my theme I format the date need to be like this: d/m/Y
    is there a way to have the same format in the datepicker input fields I have in post edit screen?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    The format specified in the date field specifies how the value is stored in the database — see this screenshot: http://www.screencast.com/t/VnS0CEBadb7

    However, you shouldn’t particularly care how the date is stored: leave that to the database. It’s not necessarily meant for humans anyway. You should only be concerned about how the date displayed in your theme files: let go of the idea of “syncing” these things. That’s the wrong way to think about this.

    Read up on the PHP date function http://php.net/manual/en/function.date.php — this is a google question really, so forgive me for not looking up every detail for you. Add those options to your print_custom_field() function as demonstrated in the docs.

    Thread Starter bluantinoo

    (@bluantinoo)

    fireproof, I don’t know why but it looks like I’m unable to explain my point.

    My concern is not about how date is formatted in theme file, but how it’s formatted in post edit screen, I mean in the datepicker input fields of wp-admin, here: http://prntscr.com/1p552c. How to control that?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    You control the format in the edit screen by changing the formatting options for your date field, but that’s my point: you shouldn’t use anything other than the MySQL format. Although it’s POSSIBLE to change the format, I strongly recommend leaving it alone. It really doesn’t matter what that date looks like in the post editor — if you try to make your users “happy” by giving them a “pretty” date format in the manager, you can shoot yourself in the foot by storing date formats that are impossible to sort.

    Thread Starter bluantinoo

    (@bluantinoo)

    Hi fireproof,
    ok then now it’s clear: what I see in the datepicker field is exactly what I will store in database.

    I was just missthinking that maybe there was some javascript formatting in the input field, that did not change the way the date gets stored.

    Do you think it’s something doable or not at all?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Although anything is possible, I would very strongly recommend that you don’t try to alter this. It’s fine to change the read-only view of something in the theme file. It’s not Ok to try to mask how data gets stored. Trying to change that will probably cause you nothing but pain and headaches.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘datepicker regional (2)’ is closed to new replies.