Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3393364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:31+00:00 2026-05-18T04:02:31+00:00

Currently for my blog I get a list of years/dates using the following code:

  • 0

Currently for my blog I get a list of years/dates using the following code:

    $monthList = array(
        1 => 'January',
        2 => 'February',
        3 => 'March',
        4 => 'April',
        5 => 'May',
        6 => 'June',
        7 => 'July',
        8 => 'August',
        9 => 'September',
        10 => 'November',
        11 => 'October',
        12 => 'December'
    );
    $nav = array();
    for ($year = 2009; $year <= date('Y'); $year++) {
        foreach ($monthList as $id => $month) {
            $this->tru->query->runRaw(array(
                'name' => 'get-headline-count',
                'sql' => 'SELECT
                        COUNT(id) as count
                    FROM 
                        wp_'.$this->getId().'_posts
                    WHERE
                        post_status = \'publish\' AND
                        post_type = \'post\' AND
                        post_parent = \'0\' AND
                        YEAR(post_date) = '.$year.' AND
                        MONTH(post_date) = '.$id.'',
                'connection' => 'article'
            ));
            $temp = $this->tru->query->getArray('get-headline-count');
            if ($temp['count'] > 0) {
                $nav[$year][$id] = $temp['count'];
            }
        }
    }

    krsort($nav);

    return array(
        'month' => $monthList,
        'nav' => $nav
    );

This was all great at first, but now that I’ve got a few years worth of data and a few months this isn’t going to cut it anymore. I’ve never done anything like this before, I usually deal with timestamps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:02:32+00:00Added an answer on May 18, 2026 at 4:02 am

    You can replace the loop with this one query

    SELECT
       YEAR(post_date) as yr, MONTH(post_date) as mn, COUNT(id) as count
    FROM 
        wp_posts
    WHERE
        post_status = 'publish' AND
        post_type = 'post' AND
        post_parent = '0' 
    GROUP BY YEAR(post_date), MONTH(post_date) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using wordpress latest version. Currently my blog is set to custom permalink
In my Wordpress Blog I'm currently using an integrated http://U.nu url-shortener. For this I've
I currently am displaying dates as follows yyyy/mm/dd in a wordpress blog (it needs
I'm currently trying to create a list of 5 blog titles of mine, where
I'm following the following blog list below and I'm having issues getting paperclip 2.3.6
I am currently working on a Wordpress blog installation. Problem i am facing is
I am currently working on a small sponsorship application(PHP/MySql) for my personal blog, and
I'm currently implementing a RESTful API (nothing serious, just for a blog engine i'm
I'm researching the prospect of incorporating a blog into my site. Currently, my site
I am currently working on my own version of membership using Entity Framework 4.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.