WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] archive by year and month (3 posts)

  1. SteveStall
    Member
    Posted 2 years ago #

    Is it possible to achieve this:

    ^ 2012(22)
    JANUARY(18)
    FEBRUARY(4)
    > 2011(123)
    > 2010(984)
    > 2009(557)

    with a single category ?

    Thanks

  2. SteveStall
    Member
    Posted 2 years ago #

    Found this code:

    $results = $wpdb->get_results
    (
    "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts
    FROM $wpdb->posts
    WHERE post_type = 'post' 						AND post_status = 'publish'
    GROUP BY YEAR(post_date), MONTH(post_date) 					ORDER BY post_date DESC"
    );

    problem is that it is not specific for a single category

    any help?
    PM

  3. SteveStall
    Member
    Posted 2 years ago #

    Found this link that solved my problem:

    http://wordpress.stackexchange.com/questions/10988/disallow-categories-from-this-mysql-query

    $tax_query = array ( array( 'taxonomy' => 'category', 'terms' => array ( 8 ), 'operator' => 'IN' ) );
    
    $clauses = get_tax_sql ( $tax_query, $wpdb->posts, 'ID' );
    
    $results = $wpdb->get_results
    (
       "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts
       FROM $wpdb->posts {$clauses['join']}
       WHERE post_type = 'post'
       AND post_status = 'publish'
       {$clauses['where']}
       GROUP BY YEAR(post_date), MONTH(post_date)
       ORDER BY post_date DESC"
    );

    Basically it provides the mySQL query for the JOIN part and the WHERE statements. In my case I change 'operator' => 'NOT IN' to 'operator' => 'IN'

Topic Closed

This topic has been closed to new replies.

About this Topic