get_queried_object not work in taxonomy page

Question

I am trying to display post count by month of current custom taxonomy in custom taxonomy page. but it display total count by month

<?php 
$post_type = "tesekkur";
$posts = get_queried_object()->term_id;
$timestamp_start = strtotime("first day of next month -1 year midnight");
$start = date("Y-m-d H:i:s", $timestamp_start);

$posts = get_posts([
    "nopaging" => TRUE,
    "post_type" => $post_type,
    "date_query" => [
        "after" => $start,
    ],
]);



// sort by month

$tab = [];

foreach ($posts as $post) {

    $month = mysql2date("F", $post->post_date);

    if (!isset($tab[$month])) {
        $tab[$month] = 0;
    }

    $tab[$month]++;

}


// display

$timestamp = $timestamp_start;
$now = time();

while ($timestamp < $now) {

    $month = date_i18n("F", $timestamp);

    $count = $tab[$month] ?? 0; // need PHP 7

    echo '<li>'."$month: $count". '</li>';


    // next month

    $timestamp = strtotime("+1 month", $timestamp);

}
?>
0
, , , , Raminer 2 years 2019-12-03T00:55:56-05:00 0 Answers 80 views 0

Leave an answer

Browse
Browse