Created
July 29, 2011 04:08
-
-
Save Javlopez/1113111 to your computer and use it in GitHub Desktop.
Sencillo script que permite extraer categorias y subcategorias de wordpress a un array
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 | |
/** | |
*@example $array_categorys = get_array_categorys(); | |
*/ | |
function get_array_categorys() | |
{ | |
$categories = get_categories(array('type' => 'post','orderby' => 'name','order' => 'ASC','hide_empty' => false)); | |
$wp_cat = array(); | |
//Get categorys parents | |
foreach($categories as $category){ | |
if($category->parent=="0" AND $category->slug != "uncategorized") | |
{ | |
$wp_cat[$category->term_id] = array( | |
"id" => $category->term_id, | |
"name" => $category->name, | |
"slug" => $category->slug, | |
"subcategorys" => array(), | |
); | |
} | |
} | |
//get subcategorys | |
foreach($categories as $category){ | |
if($category->parent!="0" AND $category->slug != "uncategorized") | |
{ | |
$subcategory = array( | |
"id" => $category->term_id, | |
"name" => $category->name, | |
"slug" => $category->slug, | |
); | |
array_push($wp_cat[$category->parent]["subcategorys"],$subcategory); | |
} | |
} | |
return $wp_cat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment