I customized a WordPress archive page which displays a list of posts filtered by a custom date field called 'email_blast_date'. I am trying to figure out how to generate a link in my header or sidebar that directs users to the archive page with the latest 'email_blast_date' day that contains published posts. I'm still a new WP developer... this is what I know:
I've got the archive page working, based off my custom field 'email_blast_date rather' rather than published date.
Archive page URL is structured and working with the "Day and name" permalink settings (domain.com/%year%/%month%/%day%/).
Any you very much in advance for your help!!
<?php
$args = array(
'post_type' => 'post',
'numberposts' => 1,
'meta_key' => 'email_blast_date',
'order' => 'DESC',
'orderby' => 'meta_value'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); endwhile;
$eb_date = strtotime(get_post_meta( get_the_ID(), 'email_blast_date', true ));
$year = date('Y',$eb_date);
$month = date('m',$eb_date);
$day = date('d',$eb_date);
$link = $year . "/" . $month . "/" . $day . "/";
?>
<a href="<?php echo esc_url( home_url( $link ) ); ?>