Hot answers tagged

47

I faced similar issue in past because I modified my date function. And then posts were displaying date if only each post has different date otherwise it returned blank. Try adding <?php echo get_the_date(); ?> instead.


26

Why does it not show? When you look at the source of the the_date() function, then you will notice two globals: global $currentday, $previousday; And then there's a rule if there's a date to display ... or not. The check is similar to the one done with is_new_day(): if ( $currentday != $previousday ) { // show date // Set global $...


21

I ran into the same problem several times, following changes worked for me in the past: while (have_posts()) : the_post(); //some html <li class="icon-date"><?php echo get_the_date( 'Y-m-d' ); ?></li> <li class="icon-time"><?php the_time( 'H:i:s' ); ?></li> Instead of the_date(), use get_the_date(). The only thing to be ...


21

In addition to birgire's solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', // Using the date_query to filter posts from last week '...


19

Call wp_update_post() with a special value for 'post_date' and 'post_date_gmt': $time = current_time('mysql'); wp_update_post( array ( 'ID' => 123, // ID of the post to update 'post_date' => $time, 'post_date_gmt' => get_gmt_from_date( $time ) ) );


16

First, your date format has to be in descending order from largest to smallest units, i.e.: year, month, day, hour, minute, second, etc., otherwise MySQL can't query or order on the field. In this example I use year - month - day: $today = date( 'Y-m-d' ); $args = array( 'post_type' => 'vehicle', 'meta_query' => array( array( ...


16

get_the_date must be used inside the Loop. For outside the loop use get_the_time. $posts = get_posts(array('numberposts'=>-1)); //Get all published posts foreach ($posts as $post){ echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format. } Consider replacing 'Y-m-d' in this example with get_option('date_format') as this will display ...


15

Alright, You can just hook into the filter pre_get_posts and check is_admin. Put this in your theme or plugin: function wpse_81939_post_types_admin_order( $wp_query ) { if (is_admin()) { // Get the post type from the query $post_type = $wp_query->query['post_type']; if ( $post_type == 'Videos') { $wp_query->set('orderby', 'date'...


15

You seemed to have solved everything but the issue with the time: found the issue %d should be %s. but I see that it saves the server time not the current timezone WordPress has a number of date/time related functions. In this case, it sounds like what you need is current_time(), which... Returns the blog's current local time in one of two formats, ...


13

get_current_user_id() give you the user id of the logged in user. And that is: you. You have to get all users: <?php $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( $user->ID ); $registered = $udata->user_registered; printf( '%s member since %s<br>', $udata->...


12

What date was/is the post published? Media uploads are added to the folder when the post/page was published, not the upload date. Was the post originally published in Feb 2015? https://core.trac.wordpress.org/ticket/10752


10

Do not use the post_date field for anything it isn’t made for. Use a post meta field instead. The post_date is bound to post_date_gmt, you would get strange side effect even you could get an earlier date into that. So create post meta fields and query those per tax query. Ignore the default field. In answer to your comment: Do not use a taxonomy. ...


10

This is not really an answer, just an attempt to find the specific context for this problem. Please install the following plugin on your site, try to set the three dates and add your result to the second <pre> in the table below. /* Plugin Name: WPSE Sysinfo */ add_action( 'admin_footer', 'wpse_sysinfo' ); function wpse_sysinfo() { $bit = ...


10

Don't use the_date(), instead use the_time(). the_date returns the date only, the_time returns the date + the time. I don't know the reason why wordpress won't return more than one date when the_date is used in a loop. But it has to do with the fact that the value is the same. If you use the_time the value is never the same, therefore it always returns the ...


10

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published. There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or post_modified_gmt dates as this will correspond ...


9

Use the fourth parameter for get_post_time(): $time = get_post_time( 'F j, Y', // format TRUE, // GMT get_the_ID(), // Post ID TRUE // translate, use date_i18n() ); get_post_time() calls mysql2date() internally, and it passes the $translate argument through. In mysql2date() we find this: if ( $translate ) ...


9

Use get_query_var() to get the date parts: $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); $day = get_query_var('day'); In wp_title() a call to get_query_var('m') is used for the month too, but I got always just a 0 as value even on an URL like /2008/09/05/. If you want to print the month name, use: $GLOBALS['wp_locale']-&...


9

Your question is pretty old, but I just wanted to add a real solution to your question. Here's a function that will return an array of years you have posts published in. You can put this function in functions.php or in a plugin or whatever you want. function get_posts_years_array() { global $wpdb; $result = array(); $years = $wpdb->...


9

This will definitely work....It worked for me... $username = get_the_author_meta( 'login', $author_id ); $args = array( 'post_type' => 'any', 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => true, 'tax_query' => array( array( '...


8

Use date_i18n(): date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) ); From the function’s description: Retrieve the date in localized format, based on timestamp. If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn't, then the date format string will be used instead. ...


8

There is no need to craft a custom SQL query in order to achieve this. Since version 4.1, WordPress's query classes have supported complex/nested meta queries. So you can craft a query like this: $args['meta_query'] = array( // Use an OR relationship between the query in this array and the one in // the next array. (AND is the default.) ...


7

Few months ago, I updated the Codex for get_users() and WP_User_Query, regarding the date_query support on the user's registration date, in WordPress 4.1+. Then I also added a simple example on how to find users that registered during the last 12 hours. But the current question is how to find users that registered today. We could simply use relative date ...


7

WordPress lets you add custom cron schedules, which is normally what you'd want to do in this situation, in conjunction with wp_schedule_event(). But, they work based on intervals rather than specific dates/times. For instance, add_filter( 'cron_schedules', 'addCustomCronIntervals' ); function addCustomCronIntervals( $schedules ) { $schedules[ self::...


7

Question and expectations While the literal form of this question is practical in context (year 1899) it is a little vague in theoretical sense. How old is old? How far into the past we might want to go? What about the future? Since WordPress had started out as blogging engine, in that contextual sense it evolved to handle following span of time: dates WP ...


6

This is quite simple: just replace the get_the_date() or the_date() with echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';


6

According to the Codex page for get_the_time(), it needs to be used in The Loop. The difference between the_time() and get_the_time() is that the former echo()es the date, and the latter returns it. There are a couple functions that do what I think you're looking for -- get the last updated date and time for a post: get_the_modified_time() and ...


6

I think this must have been solved many times here on WordPress Answers. You could also check out the examples in the Time parameters part in Codex for WP_Query. Here are two of them (slightly modified to your needs) Example 1: // Create a new filtering function that will add our where clause to the query function filter_where( $where = '' ) { // ...


5

EDIT -> while this answer still works for < WP4.4, since 4.4 support for Custom Post Types is now included in wp_get_archives() There finally is a simple, quick and easy solution for date based archives of Custom Post Types in WordPress! This has been a long standing issue that is recorded here in the WP Core Trac. It has yet to be solved but one of the ...


5

With some more googling: <?php $today = date("Y/m/j"); query_posts(array( 'post_type' => 'custompost', 'posts_per_page' => 4, 'meta_key' => 'mydate', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'mydate', 'meta-value' => $value, 'value' => $...


5

This isn't complete copy/paste code, but hopefully it's understandable enough to get you started. First step is to register your post type and add a rewrite rule to handle years/months. This will give you single events at event/post-name/, your post type archive at calendar, and handle incoming requests for calendar/yyyy/mm/. Make sure to visit your ...


Only top voted, non community-wiki answers of a minimum length are eligible