Ottenere il nome del termine dall'ID del termine?
27 nov 2013, 05:02:31
Visualizzazioni: 46.6K
Voti: 11
Non riesco a capire come ottenere il nome del termine tassonomico avendo l'ID del termine della tassonomia.
Questo è il mio codice attuale
// crea un menu a tendina della tassonomia quantità
wp_dropdown_categories(
array('taxonomy' => 'quantity_category', 'name' => 'productQuantity', 'hide_empty' => 0)
);
$quantityTerms = $_POST['productQuantity'];
$quantityTax = 'quantity_category';
Il valore di $quantityTerms
non è il "nome" della quantità ma l'ID della categoria di quantità. Quando imposta i termini dell'oggetto, crea una nuova categoria chiamata "ID#" e non la inserisce nella categoria per nome.
wp_set_object_terms( $post_id, $quantityTerms, $quantityTax, $append );

Jon Furry
187
Commenti
Tutte le risposte alla domanda
1
1
La funzione get_term_by() ti permette di ottenere il nome del termine della tassonomia a partire dall'ID.
$quantityTermObject = get_term_by( 'id', absint( $quantityTerms ), 'quantity_category' );
$quantityTermName = $quantityTermObject->name;

Rachel Baker
1.95K
27 nov 2013 06:27:52
Domande correlate