Add Date and Author to Posts

Use the following code in file template single.php (https://developer.wordpress.org/reference/functions/get_day_link/#user-contributed-notes ) : <?php $archive_year = get_the_time( ‘Y’ ); $archive_month = get_the_time( ‘m’ ); $archive_day = get_the_time( ‘d’ ); $month= get_the_date(‘M’); ?> <div class=”custom_archives”> <p> Posted on: <a href=”https://wordpress.stackexchange.com/questions/310792/<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>”><?php echo $month. ” “.$archive_day.”, ” .$archive_year; ?> </a> </p> … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)