Friday, 9 August 2013

Wordpress get_categories can not find out children directory

Wordpress get_categories can not find out children directory

I had a wordpress problem which troubled me a lot. I writed a php script
that can insert my specific data into the database of wordpress. Actually,
I deleted the initial data of wordpress and used the script to scan my
directories to initialize the tables in the database.
However, I encounterd a problem that I used the get_categories() function
to find out children directories but failed. Following is my code:
$args = Array('parent'=>'1', 'hide_empty'=>0);
echo count(get_categories($args));
The face is that there are some directories in the category with number 1,
but it prints 0. So I used cat_is_ancestor_of function to test:
echo cat_is_ancestor_of(1, 2);
It prints 1 which shows that category 2 is children of category 1. But why
get_categories returns the wrong answer? It puzzled me a lot! Could anyone
help me solve it?

No comments:

Post a Comment