• Resolved huntz

    (@huntz)


    Hello,

    I’m on a custom post type page and I’m using the code

    function getCurrentCatID(){
    global $wp_query;
    $cat_ID = get_query_var(‘cat’);
    return $cat_ID;
    }

    to get the category id but it’s not bringing anything back, it works on normal posts. Anyone got any ideas?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • It works on post (single), because posts have category in contrast to pages.

    Thread Starter huntz

    (@huntz)

    Sorry, I said custom post type page but I just mean custom post type.

    It works on normal posts but on a custom post type it doesn’t bring back anything. I’m wondering if the query takes custom post types into consideration?

    Thanks agaom

    Thread Starter huntz

    (@huntz)

    I’m basically on a custom post type post and I need to and I need to find out the category id of it :-S

    How are you assigning categories to custom post types? I set up custom posts, but was never able to assign categories, so I finally set up custom heirarchical taxonomies. Were you able to use standard categories? Did I do something wrong setting up my post type…cuz categories would have been waaaay easier. But if you are using custom taxonomies, I can help….

    Thread Starter huntz

    (@huntz)

    We managed to use normal categories so we have our old posts and new post types in the same category, lots of fun lol.

    Managed to solve this problem with this;

    function getCurrentCatID(){
    global $wp_query;
    global $post;
    $cats = get_the_category();
    $cat_ID = $cats[0]->cat_ID;
    return $cat_ID;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to get the cat id of a custom post type?’ is closed to new replies.