I have troubles with getting the posts primary set category. How should I achieve this?

My code:

global $post;
$terms = get_the_terms( $post->ID, 'event-categories');

if($terms) {
    foreach( $terms as $term ) {
        $cat_obj = get_term($term->term_id, 'event-categories');
        $cat_slug = $cat_obj->slug;
    }
}

and in my html

<div class="post_kachel <?php echo $cat_slug; ?>">
  • Anyone? If something is not clear, then please tell me - I'll try to explain it as best as I can. – SengelYTPI Nov 30 at 12:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.