Tag Info

Hot answers tagged

22

if you need the gmt_offset then <?php echo get_option('gmt_offset'); ?> this will give you an integer like 2 or -2. and if you need the timezone string use <?php echo get_option('timezone_string'); ?> this will give you a string like America/Indianapolis


10

If you can explain it in SQL, you can query for it! There are three places where we want to change the default query: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND wp_postmeta.meta_key = 'startDate' AND ...


9

You may notice that I did more or less exactly this for Matt's site: http://ma.tt. Every set of posts is grouped by the day. The basic principle is to keep track of your day in the loop, then print the date and related stuff only when it changes. Take a basic Loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_content(); ...


7

They are, very similar but with some nuances: function get_the_date( $d = '' ) { global $post; $the_date = ''; if ( '' == $d ) $the_date .= mysql2date(get_option('date_format'), $post->post_date); else $the_date .= mysql2date($d, $post->post_date); return apply_filters('get_the_date', $the_date, $d); } function ...


7

There is a function in WordPress called current_time(); which you pass either 'timestamp' or 'mysql' to and it returns a time. For more information: http://codex.wordpress.org/Function_Reference/current_time


7

I know I'm three months late, but the function you want here is get_date_from_gmt(). The function accepts a GMT/UTC date in Y-m-d H:i:s format as the first parameter, and your desired date format as the second parameter. It'll convert your date to the local timezone as set on the Settings screen. Example usage: echo get_date_from_gmt( date( 'Y-m-d H:i:s', ...


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

Yes, there isn't currently built-in support for CPT archives, but that doesn't mean you can't extend WP to provide it. I just did this myself the other day... This won't create the date-based archives you're looking for, but it will give you virtual archive behavior for custom post types. Adding the date should just be a matter of tweaking the rewrite rules ...


6

Firstly you'll need to stop storing the dates in D d.m format, the queries aren't going to be able to sort based on that data. As wyrfel pointed out, you'll need to use the alternate field option to have two fields, one that shows the pretty(or your chosen) date format, and another that holds the value you store in the DB(in a format that the queries can ...


5

I don't see anything like it in the database, so you probably have to do this yourself. To save the last login time, you can hook into the wp_login action, and save a user meta value (like [myprefix]_lastlogintime). You first read this value, so you get the previous login time, save this in the session, and then save the new login time. On the regular admin ...


5

As most template tags that start with the_ this one echoes time and not returns it (which template tags that start with get_the_ do). First the_time() fires and echoes year, then its return (null) gets concatenated and echoed with string. So: echo 'Archive for '; the_time('Y'); Or: echo 'Archive for ' . get_the_time('Y');


5

EDIT: Your problem is this: When you save your meta data, you want the date to be saved as a strtotime() date, but you want it to display the date back in the old Y-m-d format. What you need to do is save it as strtotime() and then when displaying the text back in the input, you need to reverse that strtotime()so it can be displayed properly. You can do ...


5

You would just need to format the time that is returned by current_time() with the php date() function like this: $my_time = date('G', current_time('timestamp')); The param 'G' tells the function you just want to have the hour part (0 to 23) of the date. Have a look here: http://www.php.net/manual/en/function.date.php


4

Looking at http://www.php.net/manual/en/datetime.formats.date.php I dont think strtotime will convert a DD/MM/YYYY to time correctly. However it can do MM/DD/YYYY or YYYY/MM/DD. Try using the date format of YYYY/MM/DD Or if thats not to your liking then you can use the same date format but you will have to, on save, split up the date and convert it to ...


4

Despite what the Codex says, $postarr doesn't always get passed in, so you should just use $data. $data isn't a meaningful variable name, though, so I prefer $cleanPost. I'd also try removing the priority on the filter, since it's not usually necessary. It's also a good idea to set the slug (post_name) in addition to the title, and to avoid running the code ...


3

please view the 'alternate Field' example and source code on this page. Make your alternative field a hidden one and then save the value of the alternate field rather than the visible one into your metadata. Ahh...of course your date format for the alternate field should be 'yy-mm-dd'.


3

Are you formatting the mysql2date() input string as 'Y-m-d H:i:s', as specified in the Codex? Also, why not use this same format as $date_format? EDIT: What output do you get for $last_login? The second argument in human_time_diff() is optional. Why not just omit it? That way, if you get valid output from $last_login, you should get valid output from ...


3

Conditional tags FTW. is_month() : Currently viewing a monthly archive is_day() : Currently viewing a single day archive is_year() : Currently viewing a yearly archive is_time() : Currently viewing a time-based archive (hourly, minute, or even seconds) So to test for each of these conditions, add something like this to your archive.php (or whatever ...


3

If you don't add a post_date then WordPress fills it automatically with the current date and time. To set another date and time [ Y-m-d H:i:s ] is the right structure. An example below with your code. $postdate = date('2010-02-23 18:57:33'); $new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_date' ...


3

Upgrade to PHP 5.2 or above The Error Message you see is by WordPress. It's very misleading what it basically saying is, that you need a PHP version >= 5.2 for that feature to work. Please look into your operating systems documentation or contact technical support on how to update your PHP version. For CentOS, for example: CentOS HowTos: PHP 5.1 To 5.2 ...


3

Edited again to demonstrate adding and removing filters: Include these general functions in your functions.php. These are the filters you will invoke for the loops where you want to limit your query by these two meta values: function date_check_join( $join ) { global $wpdb; $join .= " JOIN ".$wpdb->postmeta." AS startdate ON ...


3

Not sure about WordPress specifics on processing date when saving post, but it stores post's date in database under datetime type, which according to MySQL The DATETIME, DATE, and TIMESTAMP Types only has range of 1000-01-01 00:00:00 to 9999-12-31 23:59:59 and so won't go back as far as you want. So it is definitely better to store date separately (custom ...


3

You're right in that it is a WordPress function, and thus I removed my comment. However, this is still only related to WordPress, because of this being a WordPress function. This has more to do with what a timestamp is and how you can work with it. $my_time = current_time('timestamp'); $my_hour = date('G', $my_time); if ($my_hour >= 14 && ...


3

General WordPress rule: when a function starts with get, it will return the value. If it starts with the, it echoes the value. Here, you need get_the_date('d-m-Y') instead of the_date('d-m-Y').


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

The issue is that for correct output WP needs to process date through date_i18n() function. When you use date format, hardcoded in PHP code (not simply saved in PHP DATE_* constant) like 'c' - it's not available to your code and so for WP to process. System-wide fix would be to re-process date with analogous format that can be accessed by WP code: ...


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

I think your query arguments are missing meta_key, which in this case should be 'event-date'. You need it outside the meta query for orderby to work. Try this: $today = date("Ymd", strtotime(current_time('mysql'))); $args = array( "post_type" => "post", "post_status" => "publish", "posts_per_page" => -1, "cat" => 13, "meta_query" ...


2

WordPress automatically sets the server's timezone in PHP to GMT. This is to make any date manipulations consistent - and if changed, can cause some errors. This means any native functions like date will interpret any date to be in the GMT (or UTC) format. Similarly the timezone for DateTime objects will be UTC. You should not really change this, as this ...



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