For a specific section on my website I loop through some categories and get the three latest posts in that categorie and list them. Like so:

&lt;?php $categories = get_categories(array('exclude' =&gt; '1, 4, 9, 10, 2899')); ?&gt;

&lt;?php foreach ($categories as $category) : ?&gt;
    &lt;div class="subject"&gt;
        &lt;h3&gt;&lt;?php echo $category-&gt;cat_name; ?&gt;&lt;/h3&gt;
        &lt;ul&gt;
            &lt;?php $args = array(
                'cat' =&gt; $category-&gt;cat_ID,
                'posts_per_page' =&gt; 3
            ); ?&gt;
            &lt;?php if (false === ( $category_posts_query = get_transient( 'category_posts' ) ) ) {
                $category_posts_query = new WP_Query($args);
                set_transient( 'category_posts', $category_posts_query, 36 * HOUR_IN_SECONDS );
            }
            ?&gt;
            &lt;?php while($category_posts_query-&gt;have_posts()) : ?&gt;
                &lt;?php $category_posts_query-&gt;the_post(); ?&gt;
                &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;?php endwhile; ?&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;?php wp_reset_postdata(); ?&gt;
&lt;?php endforeach; ?&gt;


However, the result is not what is expected: all posts are the same across categories even though the posts don't belong to the different categories:


When I remove the transient for caching, everything works as expted.

&lt;?php $categories = get_categories(array('exclude' =&gt; '1, 4, 9, 10, 2899')); ?&gt;

&lt;?php foreach ($categories as $category) : ?&gt;
    &lt;div class="subject"&gt;
        &lt;h3&gt;&lt;?php echo $category-&gt;cat_name; ?&gt;&lt;/h3&gt;
        &lt;ul&gt;
            &lt;?php $args = array(
                'cat' =&gt; $category-&gt;cat_ID,
                'posts_per_page' =&gt; 3
            ); ?&gt;
            &lt;?php $category_posts_query = new WP_Query($args); ?&gt;
            &lt;?php while($category_posts_query-&gt;have_posts()) : ?&gt;
                &lt;?php $category_posts_query-&gt;the_post(); ?&gt;
                &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;?php endwhile; ?&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;?php wp_reset_postdata(); ?&gt;
&lt;?php endforeach; ?&gt;


How do I add chacing to this last snippet?


Question: When enumerating motivations, is it correct to write firstly, secondly, ..., or first, second, ...?
Answer: This answer at ELU suggests:


  Both are correct, however, there is "overcorrectness" in using firstly because it seems more like an adverb than first.
  
  Go on the length principle: both have the same meaning, but firstly is two characters longer than first. The language will eventually evolve to do without the longer equivalent; I'd use first.