Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasghodsian/36d1e0cb82303e03a22f27e47ae6e4c0 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/36d1e0cb82303e03a22f27e47ae6e4c0 to your computer and use it in GitHub Desktop.
Wordpress Get taxonomy and associated options & "fields"
/**
* Title: Wordpress Get Taxonomy
* Author: Mattias Ghodsian
* Description: Wordpress Get taxonomy and assosiated options & "fields"
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*
* @param boolean $getCurrent get current set "brand" and not list
* @param string $taxonomy taxonomy
* @param boolean $hide_empty hide empty terms
* return array
**/
function wpGetTaxonomy($getCurrent = false, $taxonomy = "yith_product_brand" , $hide_empty = false){
$terms = get_terms( [ 'taxonomy' => $taxonomy , 'hide_empty' => $hide_empty ] );
$data = [];
foreach ($terms as $key => $term) {
$term = (array)$term;
$term['options'] = array_merge( get_option("taxonomy_" . $term['term_id']) , get_term_meta($term['term_id']) );
$data[$term['name']] = $term;
}
// return current "brand" if set to true
if ($getCurrent == true) {
$nKey = strip_tags( get_the_term_list( $product->id, $taxonomy ) );
return $data[$nKey];
}else{
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment