Change date format

You will need to use strtotime() with Date() to make your own date format If you already know the meta key that you need you can do the following $post_meta_data = get_post_meta(get_the_ID(), ‘endDate’, true); See get_post_meta for more information about the function. Now that we have the value and going your format all you need … Read more

Converting Y-m-d to a date with a Month name? [closed]

You can use createFromFormat to re-format your date. Like so: $date = DateTime::createFromFormat(‘Y-m-d’, ‘2021-12-06’); echo $date->format(‘Y F d’); If you want your output to be anything other than “2021 December 06”, please check PHP datetime formats for all available formatting options.

Group posts by date with a list

I usually perform a simple check to see if that day has changed. <?php $day_check = ”; while (have_posts()) : the_post(); $day = get_the_date(‘j’); if ($day != $day_check) { if ($day_check != ”) { echo ‘</ul>’; // close the list here } echo get_the_date() . ‘<ul>’; } ?> <li><a href=”#”><?php the_time(); ?><?php the_title(); ?></a></li> <?php … Read more

Check post_date in pre_get_posts

You can’t really check post_date in pre_get_posts, because, well, the action fires before (pre_…) the posts have actually been fetched (…get_posts). 🙂 But, you can use $query->set() to add date parameters to the query. This is taken from an example in the WP_Query() Codex entry: <?php function wpse54142_filter_pre_get_posts( $query ) { if ( is_feed() ) … Read more

Display Current Post’s Position in Custom Taxonomy

If the post order reflect the publishing date (and note that publishing date also takes into account hour, minute and second of publication) than is pretty easy to get the order, using a query that return only post ids and then array_search to find current post id index: $query = new WP_Query( array( ‘TAXONOMY’ => … Read more

How replace post date with event date

Ok, great. It is using the posts for concerts, parties…etc. You need to create a plugin: Simply, create a folder inside the /wp-content/plugins and name is /my-events-plugin Create a new PHP file, name it my_events_plugin.php, and use the following template: https://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/ There is this tutorial that will get you to adding the custom field and … Read more

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 Remember to use a child theme..