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:
...
5
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 ...
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
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->...
4
votes
Accepted
Date not working correctly
What you did wrong here is the part date('d', $rem_days). The function date() should be used to convert timestamp to a formatted date, not to converting a time difference in timestamp to time ...
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
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
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
Display user registration date
If you want to use it for front-end, this is the best example:
//Get post author ID
$post_author_id = get_post_field( 'post_author', $post->ID );
//Get the registration date
$registered_date = ...
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
Accepted
Translate current_time
Used date_i18n instead of current_time. For example:
echo date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) );
2
votes
How replace post date with event date
i had to do it, i was looking for something very simple : just add a date event to some post to show it in archive of my news (it can be a start date and a end date also).
You need to add custom field ...
2
votes
Accepted
Update existing post dates to random dates
Question
How to change the post date to a randomly generated date?
Answer
This is fairly straightforward. What I did was to create a plugin that upon activation get all the posts, loops through ...
2
votes
Keeping post_date same as the pending post_date on privately publishing the post
In addition to the other answers, here's a small plugin that makes sure the code is only executed once. In case the data is reset by a plugin running later, try using PHP_INT_MAX -1 as priority (not ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
date × 542posts × 83
date-time × 76
wp-query × 67
custom-post-types × 54
custom-field × 51
php × 39
archives × 31
loop × 30
query × 30
meta-query × 30
order × 28
functions × 27
advanced-custom-fields × 24
post-meta × 21
timestamp × 21
query-posts × 18
categories × 17
publish × 16
filters × 15
timezones × 13
customization × 11
plugins × 10
custom-taxonomy × 10
comments × 9