I would do this with SQL query. Doing it in PHP will be a little bit slow, I guess.
This function should do the job:
function get_categories_from_year($year) {
$sql = "select term.*
from {$wpdb->terms} term
inner join {$wpdb->term_taxonomy} tax on (term.term_id = tax.term_id)
inner join {$wpdb->term_relationships} relation on (tax.term_taxonomy_id = relation.term_taxonomy_id)
inner join {$wpdb->posts} post on (relation.object_id = post.ID)
where tax.taxonomy = 'category' and YEAR(post.post_date) = %d";
return $wpdb->get_results( $wpdb->prepare($sql, $year) );
}
Related Posts:
- get_categories for custom post type with a specific custom taxonomy attached
- How can I add the featured image functionality to a custom taxonomy?
- Combine two taxonomies in a hierarchical tree
- How can I select a primary category?
- How to make custom taxonomy check boxes like ‘Categories’
- How to create non-unique sub-category slugs?
- How to get next previous category in same taxonomy?
- Getting WordPress custom taxonomy/category?
- Display empty taxonomy terms with get_terms()
- How to get the number of child categories a specific parent category has?
- How can I convert some categories to a custom taxonomy?
- Get multidimensional array that reflects category hierarchy
- Change existing taxonomy settings when using custom taxonomy
- How to get the id from the custom category?
- How can I edit the ‘Most Used’ tab in the categories meta-box to show another custom taxonomy?
- Display custom taxonomy attached to the post on post single page
- Question on using custom structures for categories
- Echo text using is_tag
- Same menu for different taxonomies to reach different content
- How to get posts using category slug in ClassiPress?
- How to set the same base url for two different taxonomies?
- Get WooCommerce product category list in functions.php
- Why use hierarchical taxonomies instead of many custom taxonomies?
- Renaming default category taxonomy?
- How to Manage and link certain custom taxonomy?
- Display List of Categories Within a Custom Taxonomy
- How to add a post with new Taxonomy without assigning to default category?
- Converting Categories (with ACF fields) to custom taxonomies
- How can I get the categories and subcategories separately?
- Get Posts Under Custom Taxonomy
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Can a Child Category Have More than One Parent?
- How can I list all the categories under a Custom Post Type (taxonomy)?
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- How to convert regular categories to custom taxonomy?
- How to Override default update_count_callback for category
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Return category slug / title from category ID
- Order Taxonomy Term by date created
- Get term by slug in Gutenberg
- How to get the depth of a category’s subcategories
- Best way to programmatically link to multiple categories (union/intersection) [closed]
- Want to hide some categories from the categories meta box in the post editor for the two specific user roles
- Taxonomies for WordPress Media Library [duplicate]
- Can I use get_adjacent_post for specific categories?
- Taxonomy filter all children
- Can you pre-check wordpress categories?
- How to filter out Categories for specific post types on WordPress Admin?
- How can i insert term in a specific language of Polylang?
- How to organize custom categories for filtering and selecting
- Custom sub taxonomy order by
- How to “group” (categorize) the Pages together?
- Get all media categories
- Custom taxonomy/category order
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Targeting Parent Category Pages
- get_terms function not returning anything
- Why custom taxomony not showing when create a post?
- Include WooCommerce product to all child categories
- Notice: Trying to get property of non-object in : custom fields category
- WP REST API not retrieving all categories
- Eliminate word from $term->name
- Custom page category taxonomy 404
- How to get posts by category and by choosing a taxonomy term?
- Is it possible to create an alias/custom taxonomy for a category name?
- Style a category from category list
- Showing HTML if Post is In Certain Taxonomy Term
- I need to exclude from a query a category and a few custom taxonomies
- Get posts in a subcategory of a chosen parent
- Assign a custom post to a custom taxonomy based on custom field value
- Natural sort / ordering wp_dropdown_categories
- Best way to categorize/populate a magazine style layout
- get_the_category – display only a single category for a post (not all categories)
- get_the_terms has strange result since version 6.0
- display category with background color
- Automatically adding tags and categories into Post Excerpt for searching
- How can i add service category here? [duplicate]
- List taxonomy terms assigned to a post in hierarchical view
- Page category filter in admin dashboard
- Limit categories to hierarchal depth of 2
- Show the parent taxonomy by creating shortcode in woocommerce?
- When creating a new product, auto assign it to all custom taxonomy woocommerce
- Post List by category and under custom taxonomy
- Using heirarchial tags or Custom taxonomies
- Create duplicate category page with content variations
- Most efficient way to display current post subcategories?
- How to echo Tags and Categories as plain text
- How can I add HTML classes for current taxonomy/term hierarchy into my pages to simplify styles?
- How to get post count including nested categories
- New Category – custom taxonomy
- How to create default categories in new installs?
- Why is my post categories not displaying?
- Check if value is a custom taxonomy category name
- Problem importing categories and sub-categories
- finding out the top 5 source ( source is a custom taxonomy ), in a given category
- Order Categories by Character Count
- Taxonomy page wpml dropdown not working
- Is it possible for post and custom post type to share a category base slug?