sstracy
sstracy

Reputation: 36

Wordpress customized archive page link via custom date field

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:

Any you very much in advance for your help!!

Upvotes: 0

Views: 1016

Answers (1)

Verba
Verba

Reputation: 388

     <?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 ) ); ?>

Upvotes: 1

Related Questions