2013-06-27 20 views
6

Ich habe ein Problem mit Kategorien und Unterkategorien in Wordpress Plugin - Woocommerce. Ich erstelle ein Skript, das eine Kategorien und Unterkategorien erstellen würde, das Problem ist, dass ich nicht vollständig verstehe, wie all das in Woocommerce DB-Struktur funktioniert.Wie werden Kategorien und Unterkategorien für Woocommerce in DB gespeichert?

Das ist, was ich in der Lage war zu tun:

in "wp_terms":

term_id | name    | slug  | term group 
20  | Parent category | parent | 0 
21  | Children category | children | 0 

in "wp_term_taxonomy": zum Teufel don

term_taxonomy_id | term_id | taxonomy | description | parent | count 
1    | 20  | product_cat |    | 0  | 0 
2    | 21  | product_cat |    | 20  | 0 

Und das funktioniert, aber warum 't:

in "wp_term_taxonomie":

term_taxonomy_id | term_id | taxonomy | description | parent | count 
1    | 20  | product_cat |    | 21  | 0 
2    | 21  | product_cat |    | 0  | 0 

Irgendwelche Kabel?

Vielen Dank für alle im Voraus. :)

+0

Was ich verstanden habe, ist, Sie wollen Kategorie/Unterkategorie von Frontend oder durch Skript erstellen, oder? – Denish

+0

Ich denke, es wird helfen, wenn Sie Ihren Code veröffentlichen, der hier nicht funktioniert. – designtocode

Antwort

0

Vielleicht, weil man der Elternteil und der andere das Kind ist, also wenn Sie diese Beziehung definieren, ist es richtig, dass das Gegenteil nicht funktionieren sollte.

6
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; 
} 
+1

Bitte beachten Sie die Formatierung Ihres Codes. – Mike

+0

'getParentCategories()' ruft alle übergeordneten Kategorien ab, aber nur die aktive übergeordnete Kategorie – Prabs

0

Sie in Tabelle wp_options für option_name suchen müssen „product_cat_children“, gibt es serialisiert Kategoriehierarchie.

Verwandte Themen