Hot answers tagged

50

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.


29

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 $...


25

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 '...


22

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 ) ) );


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 ...


18

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

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( '...


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


11

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->...


10

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']-&...


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 ) ...


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

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 ...


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

You just need get current date and add it on data_query in wp_query, Look this: <?php $getdate = getdate(); $args = array( 'date_query' => array( array( 'year' => $getdate["year"] ), ), ); $query = new WP_Query( $args ); ?> and then use loop: <?php if ( $query->have_posts() ): while ( $query->...


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 = '' ) { // ...


6

The handy thing about how ACF stores dates as YYYYMMDD is you can treat them like integers and get a similar level of functionality as if you were using "true" dates. For example, to get all dates after 1st Jan 2011, use > 20110101. Those before June 1st 2012? < 20120601. And for your case, all dates within 2004? >= 20040101 && <= ...


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 ...


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

If you wish to get posts between two dates, then use the before and after parameters in the date_query parameter, $query_string = array( 'post_type' => 'post', 'date_query' => array( 'column' => 'post_date', 'after' => '2012-04-01', 'before' => '2012-04-30' ), 'tax_query' => array( array( 'taxonomy' =&...


5

The example above disables the ordering feature by clicking columns. Sortable & for multiple custom post types: function wpse_819391_post_types_admin_order( $wp_query ) { if ( is_admin() && !isset( $_GET['orderby'] ) ) { // Get the post type from the query $post_type = $wp_query->query['post_type']; if ( in_array( $...


5

You should use date_i18n(): $timestamp = get_post_meta($post_to_edit->ID, '_single_date', true); $friendly_date = date_i18n( get_option('date_format'), $timestamp ); ?><input value="<?= $friendly_date ?>" name="_single_date" />


5

WordPress has a special function for translating dates, called date_i18n. General usage: echo date_i18n( $dateformatstring, $unixtimestamp, $gmt); Supposing you have German as your site's language this would be: echo date_i18n( 'j. F Y', false, false); You can also import the time format from the admin settings, like this: echo date_i18n(get_option('...


4

The code you are using is specifically for the month abbreviation, (Oct). You should be using this: function eventposttype_get_the_month($month) { global $wp_locale; for ( $i = 1; $i < 13; $i = $i +1 ) { if ( $i == $month ) $month =$wp_locale->get_month( $i ) ; } return $monthabbr; }


4

get_the_time() function returns the time of the current post within loop. If you want to display today's date then use date function of core php.


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