Last active
August 29, 2015 14:01
-
-
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
This file contains 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 | |
$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