sql >> Base de Datos >  >> RDS >> Mysql

¿Cómo se guardan las categorías y subcategorías de WooCommerce en DB?

function getParentCategories() {
    global $wpdb;
    $sql = "SELECT term_id as id, name, slug FROM wp_terms where term_id in (SELECT term_id FROM wp_term_taxonomy where parent = 0 and taxonomy = 'category') order by name asc";
    $parents = $wpdb->get_results( $sql );
    return $parents;
}

function getChildCategories($id) {
    global $wpdb;
    $sql = "SELECT term_id as id, name, slug FROM wp_terms where term_id in (SELECT term_id FROM wp_term_taxonomy where parent = $id and taxonomy = 'category')  order by name asc";
    $children = $wpdb->get_results( $sql );
    return $children;
}