I'm trying to find anything out there that will list posts under a specific category by date. Here's my example:

Photography (being the category name)


  • Post title shows here
  • Post title shows here
  • Post title shows here


  • Post title shows here
  • post title shows here
  • Post title shows here

I know that this is probably pretty basic wordpress, but all I can really find out there is for all categories, not just one specific one.

2 Answers 2


Even though it is not the most conventional way of doing, I would proceed like this:

Edit : precision I create a new file category.php which is the template for categories, and put this piece of code inside.

$args = array(  'post_type'=>'post',
    'posts_per_page'=> -1,

$query = new WP_Query($args);

    $years = array();
    $postList = '';
    foreach ($query->posts as $post) {

        //if we haven't proceed the year yet
        // we display it
        if(!in_array($year = get_the_date('Y',$post->ID),$years))
            $years[] = $year;

        $postList.=sprintf('<h3><a href="%1$s" title="%2$s">%2$s</a></h3>',get_permalink($post->ID),$post->post_title);


    echo $postList;


    _e('No posts sorry','your-text-domain');

  • Now, would I have to specify the category in the query args, too? Commented Mar 27, 2018 at 18:12
  • Okay, this works :) So let me understand: Will this list every year from 2018 on? Commented Mar 28, 2018 at 0:04
  • Actually, it orders the posts from the most recent to the older. It checks the publication year of each post, if we have not displayed it yet we show it.
    – Friss
    Commented Mar 28, 2018 at 4:56
  • Sorry, I'm just not that great at looking at php and knowing what it'll do. Sometimes I get lucky and can figure it out, but so, when this code runs it'll display the current year, the posts under the specified category, but when 2018 runs out and 2019 is upon us, will it keep the 2018 posts under the 2018 heading? Then start listing 2019 posts under a 2019 header? Commented Mar 28, 2018 at 12:32
  • Yes, that's it, as you described in your question.
    – Friss
    Commented Mar 28, 2018 at 12:34

Thanks for your help, Friss!

I added category_name to the query so I could draw down the photography category:

<?php $args = array( 'post_type' =>'post', 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'category_name' => 'photography' ); $photography_archive = new WP_Query( $args ); ?>

  • Glad to help :)
    – Friss
    Commented Mar 28, 2018 at 14:34

Your Answer

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

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