Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks

share|improve this question
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 '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
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.