0

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)?

1
  • 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? Commented Feb 27, 2013 at 17:49

1 Answer 1

0

Use ksort($projectsByYear)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.