WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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 '13 at 23:05
+ 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 '13 at 1:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.