Tag Info

Hot answers tagged

11

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


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


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

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


7

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


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

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

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

<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

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


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.


4

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


3

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


3

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


3

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


3

I had the same issue as you when I was dealing with events and wanted to show future events. Here is what I coded: add_action( 'init', 'change_future_posts_to_post_now' ); function change_future_posts_to_post_now() { remove_action("future_post", '_future_post_hook'); add_action("future_post", 'publish_future_posts_now', 2, 10); } function ...


3

This might work: $date = get_the_date(); $date_unix = strtotime($date); // now lets add 100 years $date_unix += (100*365*24*60*60); $echo date('U',$date_unix); The main issue this faces is that there may be a cut off/rollover around 2030~ depending on your system. In those cases, print out the current date, but without the year, then manually print the ...


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

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


3

It is unclear if you are looking for the last updated post or for the last updated date for some particular post. The answer by @PatJ assumes the former. To do the latter: $qry = new WP_Query(array('p'=>1)); var_dump($qry->posts[0]->post_modified); Or... $date = $wpdb->get_var("SELECT post_modified FROM {$wpdb->posts} WHERE ID = 1"); ...


3

There is no argument to restrict a comment query directly to a given date. You have to filter the query later: /** * Get the number of comments for a post today. * * @param int $post_id * @return int */ function t5_count_comments_today( $post_id = NULL ) { if ( NULL === $post_id ) $post_id = get_the_ID(); add_filter( ...


2

as for the document of the datapicker UI , I believe you do not need this function . the document specifies that you can use the following formats : COOKIE - 'D, dd M yy' ISO_8601 - 'yy-mm-dd' which are ,IMHO, compatible . At any rate , there are many PHP functions that will help you do time - converstion, you should look at some of them here : ...


2

I'm not sure why it is modifying the data like that when displaying, but you can use $post->post_date_gmt This will return the scheduled post date the same as it is in the DB except it's in GMT time format, so you might need to convert the time to your local time zone first (this blog post may help). Otherwise, you should be able to use it as is if ...


2

http://wordpress.org/extend/plugins/oldest-2-newest-redux/ it takes your oldest post and reposts it in the front every 24 hours, but you can change the hours on the php file in the plugin folder not sure if this is what u are looking for.


2

You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month. <?php $page = get_query_var('paged') ? get_query_var('paged') : 1; $subtractor = $page-1; $date = date("Y-m-d H:i:s"); $current_month = date('n', ...


2

For this to work reliably, the date format in the database should be yyyy-mm-dd. Comparison type should be DATE or NUMERIC. If you take the date of 25-04-2012 in present format and compare it numerically to the date 26-04-1986, you can see what the issue will be: 25042012 < 26041986 ALso- if you're doing these queries in addition to your main loop, use a ...


2

An example, that uses the posts_where filter. If you need to extend a query using the posts_clauses filter, then just exchange $where with $pieces and set $pieces['where'] .= instead of $where .=. Just drop that into your functions.php file and add some conditional tag before querying the posts. function filter_where( $where ) { // Add some ...


2

Looks like you asked this question elsewhere, PROBLEM: WordPress Support Forum SOLUTION: PasteBin AUTHOR: Alan Jackson For reference: <?php echo '<ul id="timeline">'; echo '<li>Latest</li>'; $prev_month = ''; $prev_year = ''; $args = array( 'posts_per_page' => 10, 'ignore_sticky_posts' => 1 ); $postsbymonth = ...



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