WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_categories in functions.php (WP 2.8) (8 posts)

  1. webdemar
    Member
    Posted 4 years ago #

    Hi all,

    just experienced a mayor problem with get_categories() in my themes under WordPress 2.8. The function seems to work right in any template file. But if you put

    <pre><?php print_r(get_categories()); ?></pre>

    in the functions.php it will return

    Array
    (
    [errors] => Array
    (
    [invalid_taxonomy] => Array
    (
    [0] => Invalid Taxonomy
    )

    )

    [error_data] => Array
    (
    )

    )

    In the theme options page I use a select input field to let the user pick categories. This select field is empty now due to the error.

    Anybody has the same issue and an idea how to solve this? Thanks in advance!

    Simon

  2. eight7teen
    Member
    Posted 4 years ago #

    Hey Simon! Nice to hear a voice of reason in this seemingly hopeless place... haha

    I've tried posting examples and explaining as thoroughly and simply as possible... Yet the admin(s) still say it's a theme problem and not at all related to WP itself... Odd how common sense doesn't seem to prevail here.

    http://wordpress.org/support/topic/279179?replies=12#post-1104218
    http://wordpress.org/support/topic/280256?replies=10#post-1104228

  3. Chris
    Member
    Posted 4 years ago #

    Hi,

    one more detail:

    It seems to be a timing thing: http://core.trac.wordpress.org/ticket/10160

    In my case, I'm using get_categories() to create a drop downlist to choose a category for a Featured Post blog on the front page.

    Here's my work around:

    I put the code into a function that's called by the function that needs the get_category() info. Now it works.

    Cheers,

    Chris

  4. Chris
    Member
    Posted 4 years ago #

    .. should read block not blog

  5. aesop1
    Member
    Posted 4 years ago #

    Der WupperPirat,

    Could you post your code or make it available somewhere? I was working on a similar solution, but can't get it to work.

    Thanks,

    Matt

  6. MichaelH
    Member
    Posted 4 years ago #

  7. Chris
    Member
    Posted 4 years ago #

    Hi Matt,

    take a look here: a bit of code

    Cheers,

    Chris

  8. mores
    Member
    Posted 4 years ago #

    Just realized I was able to use a code like this:
    $categories = get_categories('child_of=4&hide_empty=0&orderby=menuorder');
    Now, since "orderby" only accepts "id" or "name", if you specify something that it doesn't know, it'll give you nothing.

    I'm using "MyCategoryOrder" to order my categories, now this will basically leave me standing in the rain :(

Topic Closed

This topic has been closed to new replies.

About this Topic