2

Based on the example on http://codex.wordpress.org/Function_Reference/get_categories, I try to run get_categories function on wordpress. But the result show nothing. Is it because of the new version wordpress 3.0?

<?php 
$categories=  get_categories('child_of=10'); 
  foreach ($categories as $category) {
    $option = '<option value="/category/archives/'.$category->category_nicename.'">';
    $option .= $category->cat_name;
    $option .= ' ('.$category->category_count.')';
    $option .= '</option>';
echo $option;
}
?>

Need help on this one.

Thanks.

6
  • What does a print_r($categories) say?
    – Pekka
    Jul 3, 2010 at 13:46
  • var_dump message is "array(0) { }"
    – Willy
    Jul 3, 2010 at 13:48
  • How about get_categories() without any parameters? Does that show anything?
    – Pekka
    Jul 3, 2010 at 13:52
  • And you do have categories that contain visible (published) posts?
    – Pekka
    Jul 3, 2010 at 14:01
  • Yes, it has plenty. I am using the same data on my local as the one on www.sepakpojok.com. From the parent categories "soccer" I am trying to get its subcategories.
    – Willy
    Jul 3, 2010 at 14:12

2 Answers 2

2

I am using the same data on my local as the one on www.sepakpojok.com. From the parent categories "soccer" I am trying to get its subcategories

Are you sure that the category 'soccer' has the same ID on both servers (local and production)?

If you've manually added the categories on each, rather than copying the DB from one to the other, the ID's for the same cat could be different.

In other words, are you sure the 'soccer' category ID is 10?

1
  • I have found the reason to the problem. Since I save the data through back door, I ignore wp_term_taxonomy of "count". After I update it, the function work. Anyway thanks.
    – Willy
    Jul 5, 2010 at 18:15
1

you might want to change it to this:

$categories = get_categories(array('hide_empty' => false, 'child_of' => 10));
1
  • I was missing hide_empty, once I added it everything worked. Thanks!
    – locrizak
    Jun 16, 2012 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.