WordPress.org

Ready to get started?Download WordPress

Forums

How to get the daughter cat ID on a Cat page (2 posts)

  1. borbs
    Member
    Posted 6 years ago #

    Hi!

    On a category page, I want to show, as featured posts, the posts inside an specific subcategory.

    For example, on the MOVIES category, I want to show, on a loop, ONLY the 'OPENING THIS WEEK' category. I know how to use multiple loops and stuff, but I'd like to get the ID from this subcat, not assign manually.

    Thank you!

  2. MichaelH
    Member
    Posted 6 years ago #

    This will list all Categories that have a Category parent ID of 5

    <?php
    $subcats = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = '5'");
    foreach ($subcats as $cat) {
    echo 'this cat is a child of 5: ' . $cat->term_id;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic