Hello! Using the code below, I list the subcategories in the category specified in id_cat.

<?php if(isset($_GET['id_cat'])){ $res = mysql_query("SELECT TER.`term_id`, TER.`name` FROM `wp_terms` TER LEFT JOIN `wp_term_taxonomy` TAX ON TER.`term_id` = TAX.`term_id` WHERE TAX.`parent`='".abs(intval($_GET['id_cat']))."'"); if(mysql_num_rows($res)>0){ while($row = mysql_fetch_assoc($res)){ echo "<li><a href='firmlist.php?id_subcat={$row['term_id']}'>{$row['name']}</a></li>"; } }else{ echo 'Error!'; } }else{ echo 'Error!'; } ?> 

Tell me plz how to make it so that, in addition to the list of subcategories, you can display in the header the name of the category to which the displayed list of subcategories belongs? The category id is contained in id_cat, you need to extract the name parameter from the wp_terms table by the given id.

    1 answer 1

    I will not write, I explain the algorithm. You first pull out the category name, and then the list of subcategories. It is possible in 2 requests for convenience ..

    PS I wrote the site, there were 100 requests to the database on a certain page ... And nothing, everything works fast

    • Like this? $ head = mysql_query ("SELECT name FROM wp_terms WHERE term_id = '". abs (intval ($ _ GET [' id_cat '])). "'" "echo $ head - Aviko
    • no not like this. Why is it so difficult to read about how to write a query to the database, get data from the database, and how to get them out of the database using PHP articles to do this in nete [2 first links] [1] [1]: yandex.ru/… > $ res = mysql_query ("SELECT name FROM wp_terms WHERE> term_id = '". abs (intval ($ _ GET [' id_cat ']))). "'")> $ head = mysql_fetch_array ($ res); > echo $ head; - Artem
    • Thank you, thank you, I promise to read myself)) - Aviko
    • if (isset ($ _ GET ['id_cat'])) {$ res = mysql_query ("SELECT name FROM wp_terms WHERE term_id = '". abs (intval ($ _ GET [' id_cat '])). "" ") $ head = mysql_fetch_array ($ res); echo $ head; } else {echo 'Error!'; } Does not output ( - Aviko 6:51 pm
    • @Shrek what nonsense? What echo, at least print_r ($ head); This is how it will output an array - oxyage