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

If i have a set of years, retrieved by the loop, for every years can be more post ID. Like:

2008 => 3,7,8
2009 => 4,5,6
2010 => 9

the code is:

if (have_posts()) :
    while (have_posts()) :
        $tmp_date = //get the year;

What's the better way to put years and relative posts ID in an array (later i need also an array sorting by year)?

share|improve this question
ok, question was stupid and i've solved in this way: $projectsByYear = array(array()); and $projectsByYear[$year][] = get_the_ID(); But how can i sort the array, by year? – lucavb Feb 27 '13 at 17:49
up vote 0 down vote accepted

Use ksort($projectsByYear)

Of course every time you add something to the array it will need to be resorted.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.