Abrufen von Termnamen aus WP Term Object

Ich habe ein Array mit diesen Ausdrücken erstellt:

$taxonomies = get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => false, )); 

Und ich habe das als Rückkehr bekommen:

 Array ( [0] => WP_Term Object ( [term_id] => 79 [name] => Édességek [slug] => edessegek [term_group] => 0 [term_taxonomy_id] => 79 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [1] => WP_Term Object ( [term_id] => 55 [name] => Ételek [slug] => etelek [term_group] => 0 [term_taxonomy_id] => 55 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 0 [filter] => raw [meta_value] => 0 ) [2] => WP_Term Object ( [term_id] => 76 [name] => Glutén mentes ételek [slug] => gluten-mentes-etelek [term_group] => 0 [term_taxonomy_id] => 76 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [3] => WP_Term Object ( [term_id] => 81 [name] => Heti ajánlat [slug] => heti-ajanlat [term_group] => 0 [term_taxonomy_id] => 81 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 0 [filter] => raw [meta_value] => 0 ) [4] => WP_Term Object ( [term_id] => 49 [name] => Indiai ételek [slug] => indiai-etelek [term_group] => 0 [term_taxonomy_id] => 49 [taxonomy] => product_cat [description] => [parent] => 55 [count] => 0 [filter] => raw [meta_value] => 0 ) [5] => WP_Term Object ( [term_id] => 73 [name] => Kedvenc ételek [slug] => kedvenc-etelek [term_group] => 0 [term_taxonomy_id] => 73 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [6] => WP_Term Object ( [term_id] => 48 [name] => Krémlevesek [slug] => kremlevesek [term_group] => 0 [term_taxonomy_id] => 48 [taxonomy] => product_cat [description] => [parent] => 55 [count] => 1 [filter] => raw [meta_value] => 0 ) [7] => WP_Term Object ( [term_id] => 47 [name] => Levesek [slug] => levesek [term_group] => 0 [term_taxonomy_id] => 47 [taxonomy] => product_cat [description] => [parent] => 55 [count] => 0 [filter] => raw [meta_value] => 0 ) [8] => WP_Term Object ( [term_id] => 61 [name] => ph levesek [slug] => ph-levesek [term_group] => 0 [term_taxonomy_id] => 61 [taxonomy] => product_cat [description] => [parent] => 47 [count] => 0 [filter] => raw [meta_value] => 0 ) [9] => WP_Term Object ( [term_id] => 78 [name] => Saláták [slug] => salatak [term_group] => 0 [term_taxonomy_id] => 78 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [10] => WP_Term Object ( [term_id] => 77 [name] => Szendvicsek [slug] => szendvicsek [term_group] => 0 [term_taxonomy_id] => 77 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [11] => WP_Term Object ( [term_id] => 75 [name] => Tejmentes ételek [slug] => tejmentes-etelek [term_group] => 0 [term_taxonomy_id] => 75 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) [12] => WP_Term Object ( [term_id] => 60 [name] => Új hűsítő levesek [slug] => uj-husito-levesek [term_group] => 0 [term_taxonomy_id] => 60 [taxonomy] => product_cat [description] => [parent] => 47 [count] => 0 [filter] => raw [meta_value] => 0 ) [13] => WP_Term Object ( [term_id] => 59 [name] => Új levesek [slug] => uj-levesek [term_group] => 0 [term_taxonomy_id] => 59 [taxonomy] => product_cat [description] => [parent] => 47 [count] => 0 [filter] => raw [meta_value] => 0 ) [14] => WP_Term Object ( [term_id] => 74 [name] => Vegaséf max ételek [slug] => vegasef-max-etelek [term_group] => 0 [term_taxonomy_id] => 74 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 ) ) 

Ich brauche nur den [name] und den [slug] in 2 getrennten Arrays. Wie ist das möglich? Ich denke über die Optionen array_column und array_push

Solutions Collecting From Web of "Abrufen von Termnamen aus WP Term Object"

Hier ist eine Alternative mit dem praktischen wp_list_pluck() :

 $terms = get_terms(array( 'taxonomy' => 'category', 'hide_empty' => false, )); $slugs = wp_list_pluck( $terms, 'slug' ); $names = wp_list_pluck( $terms, 'name' ); 

wo wir das gewünschte Feld in ein Array ausreißen.

Das hört sich komisch an, aber ich habe fremde Anforderungen gesehen, also glaube ich, dass du einen guten Grund dafür hast.

 $names = array(); $slugs = array(); $terms = get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => false, )); foreach($terms as $term) { array_push($names, $term->name); array_push($slugs, $term->slug); } 

Wird diese beiden Arrays erstellen. Beachten Sie, dass ich die Variable, die Sie $taxonomies genannt haben, umbenannt habe, da es verwirrend ist, sie nach einer Sache zu benennen, wenn sie eine andere enthält (in diesem Fall enthält sie Begriffe und keine Taxonomien).