Home › Forum › Problemi Vari con WP › get_terms non funziona con tutte le taxonomy
-
AutorePost
-
-
2 Aprile 2011 alle 19:41 #17414mic3000Partecipante
Ciao a tutti,
ho scritto questo codice per ottenere tutti i terms delle mie taxonomy ma funziona solo con la taxonomy di default ossia “category”
function tax_term(){
$my_terms = get_terms("category", 'orderby=count&hide_empty=0');
$my_results = array( '-1' => 'Select one term');
foreach ($my_terms as $my_res) {
$my_results[$my_res->term_id] = $my_res->name;
}
return $my_results;
}
se al posto di "category" inserisco ad esempio il nome di una mia tassonomia ad esempio "libri" l'array è vuoto, viene restituito solo il valore -1 ossia Select one term
Qualcuno ha gia avuto questo tipo di problema?
Grazie in anticipo
-
2 Aprile 2011 alle 22:23 #82929zhenyaPartecipante
$myterms = get_terms('category', 'orderby=count&hide_empty=0');
-
3 Aprile 2011 alle 13:02 #82941mic3000Partecipante
zhenya ho provato con il tuo suggerimento ma non cambia nulla.
Con category funziona ma con le mie taxonomy no!
-
3 Aprile 2011 alle 14:13 #82943zhenyaPartecipante
Beh nel codice ci sono errori e non so se li hai corretti tutti, inoltre non ho tempo materiale per provalo in locale. Comunque io credo che uno dei plugin di questo autore faccia al caso tuo:
http://profiles.wordpress.org/users/mfields/
ad esempio quello dal nome Taxonomy List Shortcode, oppure l’altro Taxonomy Terms List .. fammi sapere.
@edit
Inoltre direi che se spieghi meglio cosa volevi fare, magari riusciamo a dare un aiuto senza dover leggere fondi di caffè..
-
3 Aprile 2011 alle 14:57 #82945mic3000Partecipante
grazie per la risposta, effettivamente ho scritto sul forum proprio perchè avevo qualche dubbio sulla correttezza del codice!
Le correzioni che ho apportato sono basate su quanto mi hai risposto precedentemente.
function tax_term(){
$myterms = get_terms('category', 'orderby=count&hide_empty=0');
$my_results = array( '-1' => 'Select one term');
foreach ($myterms as $my_res) {
$my_results[$my_res->term_id] = $my_res->name;
}
return $my_results;
}
Preferivo quindi sistemare queste poche righe di codice piuttosto che installare i plugin.
Grazie per i suggerimenti e per il tuo tempo!
-
3 Aprile 2011 alle 15:48 #82946SteveAglAmministratore del forum
Probabilmente quelal funzione viene chiamata troppo presto… qui se ne parla:
http://wordpress.stackexchange.com/questions/13480/get-terms-return-errors/13482#13482
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.