Get Child Category By Parent Category Id

  • 3 years-4 months

    Get Child Category By Parent Category Id

    • Category : wordpress
    • Viewed : 57 times
    • Posted On :
    • Posted by : Guley
    <?php
    $deptID = "7";
    $childCatID = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent=$deptID");
    if ($childCatID){
    foreach ($childCatID as $kid)
    {
    $childCatName = $wpdb->get_row("SELECT name, term_id FROM $wpdb->terms WHERE term_id=$kid");
    echo $childCatName->term_id;
    echo $childCatName->name;
    }
    ?>

     

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.