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 … Read more

Filter on one post type with taxonimy and get other post type

tax_query with an ‘OR’ relation. This means that the query will fetch posts that meet either condition: they are ‘landing-pages’ with the specified taxonomy terms, or they are any of the other specified post types without additional taxonomy constraints. $args = array( ‘posts_per_page’ => 6, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘post_type’ => array(‘news’, ‘videos’, … Read more