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.

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:

query_posts('post_type=portfolio&posts_per_page=-1');
if (have_posts()) :
    while (have_posts()) :
        the_post();
        $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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.