Forums

[resolved] get_categories() with taxonomy not working in function.php (5 posts)

  1. Akay Akagunduz
    Member
    Posted 8 months ago #

    Hi everyone, I am trying to list my custom taxonomies with get_categories() function. It's working fine in page.php file but it's not working in function.php file. If i won't use any query string in the function, it's listing my post categories fine in function.php. What's wrong? Need help ASAP, thanks.

    My code;

    <br />
    print_r(get_categories('taxonomy=slideshow-categories&post_type=slideshow'));<br />

    The result in function.php (not working);

    <br />
    Array<br />
    (<br />
        [errors] => Array<br />
            (<br />
                [invalid_taxonomy] => Array<br />
                    (<br />
                        [0] => Invalid Taxonomy<br />
                    )</p>
    <p>        )</p>
    <p>    [error_data] => Array<br />
            (<br />
            )</p>
    <p>)<br />

    The result in page.php (working fine);

    [code moderated - please follow the forum guidelines for posting code]

  2. Digital Raindrops
    Member
    Posted 8 months ago #

    The problem looks to be this part post_type=slideshow as post_type is not an argument for get_categories(), post_type is an argument for get_pages()

    I am trying to list my custom taxonomies with get_categories() function

    Have a look at get_terms()

    Have a look at WP_Query Taxonomy_Parameters

    HTH

    David

  3. Akay Akagunduz
    Member
    Posted 8 months ago #

    Hi mate, thanks for response. It's not working when i remove the post_type argument too. I just checked for get_terms() but the result is the same, it's working fine in page.php file (or any template file), but not in function.php file.

    
    print_r(get_terms('slideshow-categories'));
    

    result for function.php; (not working)

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

    and the result which I expect in page.php file (working fine)

    
    Array
    (
        [0] => stdClass Object
            (
                [term_id] => 15
                [name] => Slideshow G1
                [slug] => slideshow-g1
                [term_group] => 0
                [term_taxonomy_id] => 15
                [taxonomy] => slideshow-categories
                [description] =>
                [parent] => 0
                [count] => 2
            )
    
        [1] => stdClass Object
            (
                [term_id] => 16
                [name] => Slideshow G2
                [slug] => slideshow-g2
                [term_group] => 0
                [term_taxonomy_id] => 16
                [taxonomy] => slideshow-categories
                [description] =>
                [parent] => 0
                [count] => 1
            )
    
        [2] => stdClass Object
            (
                [term_id] => 17
                [name] => Slideshow G3
                [slug] => slideshow-g3
                [term_group] => 0
                [term_taxonomy_id] => 17
                [taxonomy] => slideshow-categories
                [description] =>
                [parent] => 0
                [count] => 1
            )
    
    )
    
  4. duck__boy
    Member
    Posted 8 months ago #

    In fucntions.php, are you trying print_r(get_terms('slideshow-categories')); before the taxonomy has been added?

    P.s. - You need to use a pastebin for long chunks of code/output.

  5. Akay Akagunduz
    Member
    Posted 8 months ago #

    @duck__boy thanks alot, that should be the point i missed! Have a good works all.

Reply

You must log in to post.

About this Topic