Skip to main content
2 of 2
added 12 characters in body
xyz
  • 41
  • 3

PHP has a built-in date() function that formats Date-objects. In your case, you would use it as follows:

echo date('Y', 1322697600);

Since you're using these query arguments to build up an array of posts, and you want to filter specifically on that, I'd recommend building a function that triggers the loop based on your desired year filter.

I have used a similar function like this one below before:

function check_post_date($filter_year) {

    // Load the custom_date meta field
    $custom_date = get_post_meta( get_the_ID(), 'custom_date', true );

    // Turn it into a string that only displays the year
    $custom_date_year = date('Y', $custom_date);

    // If the years equal, return true.
    if( $custom_date_year == $filter_year ) {
         return true;           
    } else {
        return false;
    }
}

With this, you can manipulate if the loop runs for this post.

For instance, if you want to filter on the year 2010, you can write your loop like this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php if check_post_date('2010') : ?>
        
       <!-- Your single post code goes here! -->
        
    <?php endif; ?>
    
<?php endwhile; endif; ?>
xyz
  • 41
  • 3