WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get a posts category (3 posts)

  1. romanczar
    Member
    Posted 3 years ago #

    Hi,

    I just can't find a solution or proper hint online... How can I find out a post's category slug?

    REASON:
    - Each post has 1 and only 1 category
    - I have pags which have the same slug as he category
    - I need to get the matching page ID via the page slug, which equals the category slug... crazy, hm?

    So the idea would be something like

    DUMMY CODE!!!
    
    $cat_slug = get_posts_cat_slug($post->ID);
    $page_slug = $cat_slug;
    $page_ID = get_page_ID_by_slug($page_slug);
    
    custom second loop with $page_ID

    Can anyone help me alittle bit, please?

    Kind regards
    Czar

  2. Hax
    Member
    Posted 3 years ago #

    Try

    <?php
    foreach( (get_the_category( $post->ID ) ) as $category) {
        echo $category->category_nicename . ' ';
    }
    ?>

    http://codex.wordpress.org/Function_Reference/get_the_category

  3. romanczar
    Member
    Posted 3 years ago #

    THANKS!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.