I'm trying to display posts on the homepage from the current year only. I am using the following:

<?php if ( is_front_page()) { ?>
    <?php $current_year = date('Y');  ?>
    <?php query_posts( "&year=$current_year&order=DESC"); ?>
<?php } ?>

Yet it doesn't seem to work. I also tried:

<?php query_posts( "&year=' + $current_year + '&order=DESC"); ?>

But that doesn't seem to work either. Can anyone help?


  • 2
    Doesn't seem to work in what way? If is_front_page returning true? Also, you should seriously consider using WP_Query instead of query_posts.
    – vancoder
    Apr 9, 2013 at 23:05
  • 1
    + is not a concatenation operator in PHP so your second attempt wouldn't work, plus you've actually passed the + in the string and I don't think you meant to. You have a string literally like "&year=' + 2013 + '&order=DESC". It should be '&year='.$current_year.'&order=DESC' but that is equivalent to the code in double quotes.
    – s_ha_dum
    Apr 10, 2013 at 1:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy