Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Human Time Diff

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #165411
    gilgimech
    Participant

    Does anyone know how or if you can turn off the human time diff on the admin tables for a custom post type?

    I’m making a plugin using s custom post type and I want the actual date displayed in the date column, not the human time diff ( “Posted 1 Hour Ago” ).

    #165417
    Alen
    Participant

    I’m not sure what you are trying to do but human_time_difffunction is responsible for determining this functionality. And this function takes in two arguments:

    $from – Unix timestamp from which the difference begins.
    $to – (Optional) Unix timestamp to end the time difference. Default becomes time() if not set.

    Source.

    turn off the human time diff on the admin tables

    There’s no information in the tables about the “diff”, the date at which the post was created, get’s passed to this function which determines the human readable format. You can just query for the date and deal with it how you see fit, skipping the function.

    #165420
    gilgimech
    Participant

    Basically I don’t want the human time diff. I just want the date. So instead of “Posted 1 Hour Ago” have the date 03/11/2014.

    I could just add a custom column with the date, but I was just wondering if there was a way to use the default date column without the human time diff output.

    #165432
    Alen
    Participant

    Show us the code responsible for displaying “Posted 1 Hr Ago”, how are you getting this output?

    #165438
    gilgimech
    Participant

    No, there’s no code. It’s just the default date column. You can check the WordPress core if you want to see how WordPress displays the admin columns.

    It’s OK, I was just wondering it there was a way.

    #165443
    Alen
    Participant

    Go to wp-admin/includes folder and look for the file class-wp-posts-list-table.php, then go to the line 634, you will see this:

    $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
    

    change this line to:

    $h_time = sprintf( __( '%s' ), gmdate('Y/m/d g:i:s A', $time) );
    

    This will display as this:

    2014/03/11 8:08:54 PM
    Published
    

    in the Date column.

    Now, I’m not sure how to overwrite this without hacking WP core.

    Hope that helps,
    -Alen

    #165445
    gilgimech
    Participant

    Alen,

    Thanks, but I think you missed the point. I was just wondering if anyone knew how to change this. Hacking the core is a bad idea. I would never recommend doing that.

    If Anyone else knows of a way I’d a appreciate it.

    #165453
    Alen
    Participant

    I was just pointing you out to the class that handles this functionality. As I said, not sure how to override the class method as it stands now. I was never suggesting you SHOULD hack the core.

    #165457
    gilgimech
    Participant

    Ah,
    That’s cool. I wasn’t implying anything. I Appreciate your help though.

    #165551
    mcjohnst
    Participant

    @gilgimech , Did you ever find a solution to this without hiding the default date?

    I was tinkering with it the other day and it appears the default column headers can’t be messed with too much. The only solution I found was to unset the the default and creating a new column with custom formatting.

    Would be sweet if there’s some obscure filter / hook that can do this.

    #165566
    gilgimech
    Participant

    mcjihonst

    Yeah, making a new custom column is the only I’ve been able to achieve this. I have a feeling this is one of those annoying assumptions that WordPress makes.

    #165797
    Andy Howells
    Participant

    Wait – why not just use the_time(); ?

    #165859
    gilgimech
    Participant

    OK,

    When you make a custom post type there are two default columns on the admin table. The title and The Date. The default date columns uses the human time diff by default. So when you publish a post it’ll say “1 minute ago Published”. It even does this on the basic “Posts” post type.

    I was wondering if there was a way to use the default date column, but use an actual date format e.g. “03/14/2014” instead of the human time diff “1 minute ago Published”.

    Yes, I can make a custom column and use the_time(), but that’s not what I was asking about.

    #165865
    Andy Howells
    Participant

    I could be wrong but I think all posts (regardless of them being custom post types) still have a time stamp accessible via the_time();

    #165866
    gilgimech
    Participant

    Yes and no,

    There’s actually two settings. When the admin was upgraded to the new style, now there’s two display options now. One with all stuff like comments, categories, etc.That one does have a number format for the date. The one that is the default now, is the option with just the title and the date with human time diff.

Viewing 15 posts - 1 through 15 (of 25 total)
  • The forum ‘Back End’ is closed to new topics and replies.