Created
July 13, 2021 19:33
-
-
Save jorpdesigns/3adbe338249ae6fff6a5fb73d85bda18 to your computer and use it in GitHub Desktop.
Function for querying taxonomy terms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function taxonomy_terms_query() { | |
// Parameters available here: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters | |
$args = array( | |
'taxonomy' => 'product_cat', | |
'child_of' => 5, // Get child terms of category with ID 5 | |
'parent' => 5, // Get direct-child terms of category with ID 5 | |
); | |
$categories = get_categories($args); | |
foreach ($categories as $category) { | |
$categoryID = $category->term_id; | |
$categoryName = $category->name; | |
$categorySlug = $category->slug; | |
$categoryTaxonomy = $category->taxonomy; | |
$categoryDescription = wpautop( $category->description ); | |
$categoryParent = $category->parent; | |
$categoryParents = get_ancestors($categoryID, $categoryTaxonomy); | |
$categoryCount = $category->count; | |
$thumbnail_id = get_term_meta( $categoryID, 'thumbnail_id', true); | |
$categoryImage = wp_get_attachment_image($thumbnail_id, $size = 'full'); | |
$categoryLink = get_category_link( $categoryID ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment