Custom Posts – selecting from certain years
-
Hi,
I am currently working on a horse trainer website which lists all the horses by their age. e.g. 4 year olds, 3 year olds etc. The horses are a custom post called horse.
I am currently using this code
<?php
$mypost = array(
‘post_type’ => ‘horse’,
‘date_query’ => array(
array(
‘column’ => ‘post_date_gmt’,
‘before’ => ‘4 years ago’,
‘after’ => ‘5 years ago’
)
)
);
$loop = new WP_Query( $mypost );
?>Which selects the 4 year olds perfectly from their date of birth. I’ve now found out that the horses age isn’t taken from their actual date of birth it’s taken from the 1st of January in the year they were born.
I’m struggling with the code to detect the current year and then -1 year for 1 year olds, -2 years for 2 year olds etc.
Any help appreciated. Thank you.
The topic ‘Custom Posts – selecting from certain years’ is closed to new replies.