Tag Info

Hot answers tagged

15

See this special note about using the `the_date' SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or ...


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


9

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


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

the_date() prints the date only if the same date was not printed before. No, that's not consistent with other similar functions. But that’s how it worked in WordPress’ ancestor b2/cafelog, and backwards compatibility always trumps logic … :) To print the date always use get_the_date() <?php echo get_the_date(); ?> or <?php echo mysql2date( ...


8

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


8

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


7

The reason it's going to be infinite is that every time you save the post, it's calling change_year...which then calls wp_update_post ... which fires the save_post filter. After some review and research, I'm thinking that you should probably avoid the save_post filter. Try using this filter: ...


7

Yes, as you - so far - have no publish date. You could use $post->post_modified, which will always be the date of the latest modification to the post data. Debug: Try hooking into the filter and dump both vars: function date_dump_callback( $date, $d ) { echo '<pre>'; print_r( $date ); print_r( $d ); echo '</pre>'; return $date; ...


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


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

Some countries use a Daylight Saving Time (DST): Typically clocks are adjusted forward one hour near the start of spring and are adjusted backward in autumn. Sometimes there is no 2 am. Sometimes you get 2 am two times. To avoid cron jobs running twice or not at all WP needs the GMT (or more precise: UTC). UNIX time stamps cannot be used because they ...


5

Check out wp_cron and the cron_schedules filter. There are lots of good tutorials out there like this one from WPTuts or this one from Viper007Bond.


5

I'm not sure about a plugin, but you can definitely add custom meta that allows you to set the event date, or even an event daterange (my preferred way of handling this is an event date and a duration, cuts down on calculations in the backend and is generally easier to understand, but ymmv). This allows you to keep your post dates in order while maintaining ...


5

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


5

<p> <?php the_time() ?> </p> It helps with separation of concerns and increases readability of code as well as being consistent with WordPress coding standards and the default coding style. The first method you attempted is completely invalid, the_time() only accepts 1 parameter, the date format. The second method has roots in ...


4

I believe all the info you need is in the PHP Manual for Date/Time. Also, it is recommended that you use get_the_date(); instead of the_date(); Get them month in 3 cap letters? M is the right format character that outputs a short textual representation of a month (3 chars). Why can't you use CSS to capitalize all the three letters? I mean, ...


4

Use the Time Parameters in WP_Query() Quoting example from the Codex: Return posts from the last 30 days: // This takes your current query, that will have the filtering part added to. $query_string = array( 'post_type' => 'post', 'tax_query' => array(array( 'taxonomy' => 'post_format', 'field' => ...


4

First of all rewrite handling can become very complicated very quickly - particularly when your desired structure conflicts with WordPress' default behaviour. The best advice is probably to just avoid such conflicts rather than try to resolve them. With that as a premable... WordPress generates rewrite rules from various sources: from registered post types, ...


4

That's because that's what those functions do. For example: http://codex.wordpress.org/Function_Reference/get_the_date Use the PHP date() function


4

That format is almost readable by strtotime. Remove the commas and it will convert. $t = '27 January, 2012, 5:05 AM'; $t = str_replace(',','',$t); $t = strtotime($t); echo date('Y-m-d H:i:s',$t);


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.


4

The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { ...


4

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


4

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


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


3

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


3

In your wp_list_comments callback function, you can call get_userdata to get any additional comment author data: $userdata = get_userdata( $comment->user_id ); echo 'Registered: ' . $userdata->user_registered; // format the date // Sunday January 13th 2013 echo 'Registered: ' . date( 'l F jS Y', strtotime( $userdata->user_registered ) );


3

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


3

If the post order reflect the publishing date (and note that publishing date also takes into account hour, minute and second of publication) than is pretty easy to get the order, using a query that return only post ids and then array_search to find current post id index: $query = new WP_Query( array( 'TAXONOMY' => 'TAXONOMY TERM', ...



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