Wordpress get_categories can not find out children directory -


i had wordpress problem troubled me lot. writed php script can insert specific data database of wordpress. actually, deleted initial data of wordpress , used script scan directories initialize tables in database.

however, encounterd problem used get_categories() function find out children directories failed. following code:

   $args = array('parent'=>'1', 'hide_empty'=>0);     echo count(get_categories($args)); 

the fact there directories in category number 1, prints 0. used cat_is_ancestor_of function test:

    echo cat_is_ancestor_of(1, 2); 

it prints 1 shows category 2 children of category 1. watched mysql database, category 2 indeed son directory of category 1. why get_categories returns wrong answer? puzzled me lot! me solve it?

you can child category of parent category following way

   <?php     $subcategories = get_categories('&child_of=1&hide_empty'); // list subcategories of category '4' (even ones no posts in them)     echo count($subcategories);     echo '<ul>';     foreach ($subcategories $subcategory) {       echo sprintf('<li><a href="%s">%s</a></li>', get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));     }     echo '</ul>';     ?> 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -