Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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 ...
Gavin's user avatar
  • 384
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' => '...
Pravin Work's user avatar
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: ...
J.D.'s user avatar
  • 3,915
6 votes

Converting Unix timestamp to wordpress date

You should use date_i18n(): $timestamp = get_post_meta($post_to_edit->ID, '_single_date', true); $friendly_date = date_i18n( get_option('date_format'), $timestamp ); ?><input value="<?= ...
Minh Tri's user avatar
  • 3,419
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 ...
cjbj's user avatar
  • 14.6k
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( '...
pingle60's user avatar
  • 183
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 ...
slashbob's user avatar
  • 307
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: ...
haze's user avatar
  • 41
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 ...
Rarst's user avatar
  • 99.7k
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->...
Johansson's user avatar
  • 15.3k
3 votes

Limit content by user registration date

I have just made this code you can try out: add_filter( 'the_content', 'restrict_access' ); function restrict_access( $content ) { $user_info = wp_get_current_user(); // Get logged in user info ...
Kim Vinberg's user avatar
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(); $...
Lou Jonker's user avatar
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','...
Janith Chinthana's user avatar
3 votes

Date and time format for UK in a custom post type

Assuming you want 24 hour time, you want something like jS M Y H:i:s. You can check wordpresses own Formatting Date and Time reference for further details.
ToniWidmo's user avatar
  • 335
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 ...
jave.web's user avatar
  • 477
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 ...
Uriahs Victor's user avatar
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
Ramcharan's user avatar
3 votes

WP_Query orderby date not working

Adding 'suppress_filters' => true into the $args array did sorting in the order I needed.
Vital Rulinski's user avatar
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 ...
Paul 'Sparrow Hawk' Biron's user avatar
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', ...
Picard's user avatar
  • 1,145
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.
birgire's user avatar
  • 67.4k
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....
Damien Carbery's user avatar
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 ...
funkysoul's user avatar
  • 190
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....
jdm2112's user avatar
  • 3,676
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 ...
Krzysiek Dróżdż's user avatar
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 '...
Cubakos's user avatar
  • 336
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 ...
Sally CJ's user avatar
  • 39.3k
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 ...
Jacob Peattie's user avatar
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')) ?>
Osama Elzero's user avatar
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 ...
N Rohler's user avatar
  • 121

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