- This topic is empty.
-
AuthorPosts
-
March 11, 2014 at 8:21 am #165411
gilgimech
ParticipantDoes 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” ).
March 11, 2014 at 10:09 am #165417Alen
ParticipantI’m not sure what you are trying to do but
human_time_diff
function 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.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.
March 11, 2014 at 10:25 am #165420gilgimech
ParticipantBasically 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.
March 11, 2014 at 11:52 am #165432Alen
ParticipantShow us the code responsible for displaying “Posted 1 Hr Ago”, how are you getting this output?
March 11, 2014 at 12:38 pm #165438gilgimech
ParticipantNo, 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.
March 11, 2014 at 1:20 pm #165443Alen
ParticipantGo to
wp-admin/includes
folder and look for the fileclass-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,
-AlenMarch 11, 2014 at 1:35 pm #165445gilgimech
ParticipantAlen,
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.
March 11, 2014 at 2:07 pm #165453Alen
ParticipantI 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.
March 11, 2014 at 2:11 pm #165457gilgimech
ParticipantAh,
That’s cool. I wasn’t implying anything. I Appreciate your help though.March 12, 2014 at 10:41 am #165551mcjohnst
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.
March 12, 2014 at 12:27 pm #165566gilgimech
Participantmcjihonst
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.
March 14, 2014 at 9:29 am #165797Andy Howells
ParticipantWait – why not just use the_time(); ?
March 14, 2014 at 2:51 pm #165859gilgimech
ParticipantOK,
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.
March 14, 2014 at 3:39 pm #165865Andy Howells
ParticipantI could be wrong but I think all posts (regardless of them being custom post types) still have a time stamp accessible via the_time();
March 14, 2014 at 3:44 pm #165866gilgimech
ParticipantYes 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.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.