serie Ritorno di categorie a funzione PHP
-
16-10-2019 - |
Domanda
Sto cercando una funzione che recuperare i nomi e gli ID di tutte le categorie che l'output volontà una casella di controllo, o mi danno i dati in modo da poter eseguire un ciclo.
<input type="checkbox" name="category" value="category_id" /> Category 1
<input type="checkbox" name="category" value="category_id" /> Category 2
<input type="checkbox" name="category" value="category_id" /> Category 3
<input type="checkbox" name="category" value="category_id" /> Category 4
<input type="checkbox" name="category" value="category_id" /> Category 5
Soluzione
questo dovrebbe farlo:
$categories = get_categories();
foreach( $categories as $category ) {
echo '<input type="checkbox" name=' . $category->slug . '" value="' . $category->term_id . '" /> ' . $category->name . '<br />' . "\n";
}
ed è possibile modificare / ordinare la lista alimentando argomenti di get_categories()
:
http://codex.wordpress.org/Function_Reference/get_categories
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange