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 to display non-hierarchical taxonomy as terms with checkboxes?
- How can I list all the categories under a Custom Post Type (taxonomy)?
- Use tag interface for hierarchical taxonomy?
- Using URL parameters, list posts from category and custom taxonomy
- Different templates for parent and children categories/taxonomies
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- How to Override default update_count_callback for category
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Custom post type taxonomy template
- Order Taxonomy Term by date created
- Any way to assign Post Categories and Tags to Links?
- Want to hide some categories from the categories meta box in the post editor for the two specific user roles
- How to export/import categories and keep their IDs?
- How to use wp_category_checklist()?
- Get all sub-categories of a parent category
- Can I use get_adjacent_post for specific categories?
- Specifying multiple categories in URL (permalink)?
- Should the actual /category/ directory be 404? Is that normal WP behaviour
- Limit number of terms that a custom taxonomy can save per custom post type
- Can you pre-check wordpress categories?
- Display Taxonomy Terms in an option tag with value being the slug
- category filter doesn’t work in WPML
- How can i insert term in a specific language of Polylang?
- Get Posts Under Custom Taxonomy
- Filtering *out* a taxonomy from the admin post list
- category image taxonomy
- Categories overview that links to page displaying posts
- How to “group” (categorize) the Pages together?
- Is There a Difference Between Taxonomies and Categories?
- Get all media categories
- Custom taxonomy/category order
- How can I improve this taxonomy treating approach?
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- get_terms function not returning anything
- Why custom taxomony not showing when create a post?
- How to display parents category and child category separately for a specific post?
- Get Categories Where Taxonomy Equals ‘n’
- Having a template per category? Bad for server overhead?
- How to display a value inside a post with a specified category from a category custom field? [closed]
- Grandchild Term Things Grandfather Term is It’s Parent
- What Must to Display the “mysite.com/category” URL?
- Custom page category taxonomy 404
- How to get posts by category and by choosing a taxonomy term?
- Get posts in a subcategory of a chosen parent
- Natural sort / ordering wp_dropdown_categories
- Best way to categorize/populate a magazine style layout
- Displaying posts of given category
- Automatically adding tags and categories into Post Excerpt for searching
- How can i add service category here? [duplicate]
- Show subChild categories
- List taxonomy terms assigned to a post in hierarchical view
- WordPress 5.4 and higher: Filter posts by category 1 AND category 2 in API requests
- Automatically add custom taxonomy to posts in a category
- Ordering terms whilst in loop
- 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
- WordPress Portofolio Conditional Templating – functions php
- Parent Category and Subcategory default text generated with category
- Post List by category and under custom taxonomy
- Create duplicate category page with content variations
- Most efficient way to display current post subcategories?
- How to add additional field to Add new category part (without plugin use) [closed]
- Category and tags goes 404
- How to create default categories in new installs?
- 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
- list taxonomy based on taxonomy
- Show parent-child relationship for categories in the wordpress admin
- Order Categories by Character Count