Error counting posts of category

Every time you step through the outermost foreach() loop, your $total_count gets reset.

Try this:

$categories = get_categories([
     'hide_empty' => 0,
     'parent'     => 0,
]);

$total_count = 0;
                                
foreach ($categories as $category) {
    $subcategories = get_categories([
        'hide_empty' => 0,
         'parent'     => $category->term_id,
    ]);
                                
    $total_count += $category->count; // Adds the main category count
                                
    foreach ($subcategories as $subcategory) {
        $total_count += $subcategory->count; // Add subcategory counts
    }
                                
    echo '<input type="checkbox" data-select="sectionFilter" id="section_' . $category->term_id . '" value="' . $category->term_id . '">';
    echo '<label for="section_' . $category->term_id . '">';
}

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino