Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Are you thinking of something like this?
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( absint( get_the_date( 'n' ) ) <= 6 ) {
// First half of year
...
} else {
// Second half of year
...
}
}
}
I found this elsewhere and it worked for me...
if( (int)get_the_time( 'm' ) <= 6 ) {
echo 'Some time between January and June.';
} else {
echo 'Some time between July and December.';
}