Skip to content

Instantly share code, notes, and snippets.

@jprieton
Last active August 29, 2015 14:01
Show Gist options
  • Save jprieton/992a65b68e896d06424c to your computer and use it in GitHub Desktop.
Save jprieton/992a65b68e896d06424c to your computer and use it in GitHub Desktop.
Obtener la lista de subcategorias pertenecientes a la misma categoria principal de la subcategoria actual en WordPress
<?php
$term_id = (int) get_query_var('cat');
$current_term = get_term($term_id, 'category');
if ($current_term->parent !== 0) {
$is_parent = FALSE;
while (!$is_parent) {
$current_term = get_term($current_term->parent, 'category');
if ($current_term->parent == 0) {
$is_parent = TRUE;
}
}
}
$term_childrens = (array) get_term_children($current_term->term_id, 'category');
foreach ($term_childrens as $term) {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment