get_queried_object error How to show post count by month in the taxonomy page

Can anyone help me please. i want to show custom post type count by month of taxonomy in archive page for current year.
Example:
January 24
February 43
March 5
April 6
and etc.
This code is help ful but it display total post count instead of display taxonmy post count

    <?php
global $wpdb;
$res = $wpdb->get_results(
    "SELECT MONTH(post_date) as post_month, COUNT(ID) as post_count " .
    "FROM {$wpdb->posts} " .
    "WHERE post_date BETWEEN DATE_SUB(NOW(), INTERVAL 12 MONTH) AND NOW() AND post_type="tesekkur" " .
    "AND post_status="publish" " .
    "GROUP BY post_month ORDER BY post_date DESC", OBJECT_K
);

$postCount= 0;
$len = count($looper);

$cur = absint(date('n'));
if($cur > 1)
{
    $looper = array_merge(range($cur+1, 12), range(1, $cur));
}
else
{
    $looper = range(1, 12);
}

$out="0,";
$postCount="0";
$len = count($looper);
foreach($looper as $m)
{


    $month = date_i18n('F', mktime(0, 0, 0, $m, 1));

    $out .= sprintf(
        '%s %d',
        $month,
        //'',
        isset($res[$m]) ? $res[$m]->post_count : 0
    );
    if ($postCount!= $len-1) {
        $out .= ',';
    }

    $postCount++;

}
//$out .= '</ul>';

echo $out; ?>

i tried to do like this but gave error

function get_queried_object() {
    global $wp_query;
    return $wp_query->get_queried_object();
$res = $wp_query->get_results(
    "SELECT MONTH(post_date) as post_month, COUNT(ID) as post_count " .
    "FROM {$wp_query->posts} " .
    "WHERE post_date BETWEEN DATE_SUB(NOW(), INTERVAL 12 MONTH) AND NOW() AND post_type="sikayet" " .
    "AND post_status="publish" " .
    "GROUP BY post_month ORDER BY post_date DESC", OBJECT_K
)} ;

0

Leave a Comment