logo

This is an old version of this answer!

Return to the current answer
Hi, according to the documentation

When you assign multiple categories to a post, only one can show up in the permalink. This will be the lowest numbered category


With this in mind the code is very simple:


$args = array('order' => 'ASC');
$categories = wp_get_post_categories(get_the_ID(), $args);
$your_category = $categories[0];


After this your_category will contain the ID of the category in the slug of the current post

Max | 01/05/10 at 6:02pm

This is an old version of this answer!

Return to the current answer