16
votes
Get list of years when posts have been published
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 ...
16
votes
Accepted
WP_Query orderby date not working
This will definitely work....It worked for me...
$username = get_the_author_meta( 'login', $author_id );
$args = array(
'post_type' => 'any',
'orderby' => 'date',
'order' => '...
10
votes
Accepted
How to handle optional end date in compare clause in meta_query
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:
...
6
votes
Modify Date Format to German
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 ...
5
votes
How to get posts published between a date and today?
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(
'...
5
votes
Accepted
Get posts by meta value with date
Depends what you are getting back from the 'date_event' post-meta field.
That's probably the culprit here -- if it's an actual date with a month and day, it's not going to match what you are getting ...
4
votes
How to get post creation date?
I needed the same info and just figured out by myself. You have to make a custom query to get the first _wp_old_date from the postmeta table as @dipak_pusti suggested. Run the following statement:
...
4
votes
Accepted
Date, Time, and Timezones
What is the purpose of the timezone setting in the Admin -> Settings section?
Since WordPress handles time zone on its own (separately from native PHP functionality) that is where the setting made ...
4
votes
Accepted
How can I hide posts that are over 2 years old
You can use the pre_get_posts hook to modify the main query:
add_action( 'pre_get_posts', 'filter_old_posts' );
function filter_old_posts($query){
if( !is_admin() && $query->...
3
votes
Accepted
Modify Date Format to German
I have added the following code to child theme function and it works,
add_filter('the_time', 'modify_date_format');
function modify_date_format(){
$month_names = array(1=>'Januar','Februar','...
3
votes
Modify Date Format to German
go to admin follow 2 simple steps
Date Format - Custom : j. F Y
Change Site Language which one you want change and then save
3
votes
Get list of years when posts have been published
You could use this function to get all the post years in a array, which you could use to loop with.
$terms_year = array(
'post_type' => array('YOUR_CPT'),
);
$years = array();
$...
3
votes
Arrange Posts By Date In Order Of Closest To The Current Date
I know this is old, but ordering by DESC does not make sense for this case.
You select DATEs >= CURRENT_DATE, now you want to display first the one closest to today, let's say tomorrow and then ...
3
votes
How to get the post publish date outside the loop?
You can use get_post() or get_post_field() for this, both work outside the loop.
$post_object = get_post($id);
$post_date = date( 'F jS, Y', strtotime( $post_object->post_date ) );
A full list of ...
3
votes
WP_Query orderby date not working
Adding
'suppress_filters' => true
into the $args array did sorting in the order I needed.
3
votes
Accepted
Keeping post_date same as the pending post_date on privately publishing the post
@Howdy_McGee is on the right track in his comment: by the time transition_post_status is fired, the post has already been updated (i.e., written to the db).
What you need to do is hook into ...
3
votes
Accepted
Human Time Diff, change mins to minutes
You can do:
echo str_replace('mins', 'minutes', human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago');
Update:
The same using filter as suggested:
add_filter('human_time_diff', ...
3
votes
Accepted
Display date only once for a each set of posts relating to that date
Just use the_date(), it has this as a built-in feature.
See the dev docs for more info.
3
votes
Why did my most recent article fall behind an older one on my site?
The Side Eye post is a sticky.
See: https://codex.wordpress.org/Sticky_Posts
In the Publish meta box (top right of Edit Post page), under Visibility it has "Stick this post to the front page" checked....
3
votes
Worpdress function for difference dates
Put this in the appropriate template.
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
Normally the php file you should look for would be entry-meta.php
...
3
votes
Accepted
How to add 2 hours to the wordpress time formed with current_time("mysql", false)?
The WordPress current_time() returns the current time in the format specified in the first parameter. In your example code, this is the mysql value. The second parameter represents a timezone option....
3
votes
Accepted
WP_Query meta_query >= date
What is missing? One tiny detail... And it's easy to overlook...
the_field('datum_event');
Prints the field using the format you've defined in field settings. But... It has nothing to do with how ...
3
votes
Accepted
Remove "at" string from wordpress comment date
Most likely, the 'at' is coming from the value of $comment->comment_date. If that is the case, and since we have to do with string, you could pass it from str_replace first, in order to remove the '...
3
votes
Accepted
Ordering posts by custom field named "date" in backend
The main issue in your code is this part: $query->set('orderby','meta_value_date'); whereby you should use meta_value and not meta_value_date. (There is meta_value_num, but that's not suitable for ...
3
votes
How to display *block number* instead *date value* on Wordpress posts?
I have no idea what a 'block number' is, but when themes output the date for a post they will use either the_date() or the_time() (or both). You can replace the output using the filters the_date() or ...
2
votes
How to get the post publish date outside the loop?
Some Modern soultions
Solution One
<?php echo get_the_date('j F Y', get_the_ID()) ?>
Solution Two
<?php the_time(get_option('date_format')) ?>
2
votes
Changing the post date and time with function
The selected answer is perfect for modifying the "publish date", but in my case I wanted to change the "last modified" date (post_modified and post_modified_gmt in the db). The ...
2
votes
Display user registration date
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
printf(
$table,
'Registered',
date( "M Y", strtotime( $registered ) )
);
2
votes
Complex date range with WP_Query and BETWEEN
It's a little hard to think in meta_query code for complicated case like this and without access to data. :)
What you have working can be expressed as two following conditions:
start_date BETWEEN ...
2
votes
How to remove published date <pubDate> from RSS feed
Note that if you remove the <pubDate> tag from the rss2 feed, then it will become unvalid.
So you don't want to do that!
If it's empty:
<pubDate></pubDate>
then the feed will ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
date × 542posts × 83
date-time × 75
wp-query × 68
custom-post-types × 54
custom-field × 51
php × 38
archives × 31
meta-query × 31
loop × 30
query × 30
order × 28
functions × 27
advanced-custom-fields × 24
post-meta × 21
timestamp × 21
query-posts × 18
categories × 17
filters × 16
publish × 16
timezones × 13
customization × 11
plugins × 10
custom-taxonomy × 10
comments × 9