In questo tutorial WordPress imparerete come creare una funzione che ricava l’ID di una categoria, passandogli come parametro il suo nome.

All’interno del file functions.php scrivete:

 
function get_category_id($cat_name){
$term = get_term_by(‘name’, $cat_name, ‘category’);
return $term->term_id;
}
 

ESEMPIO APPLICATO

 
$category_ID = get_category_id(‘Tutorials PHP’);
 

Share on FacebookCondividi su facebook

fonte: www.sastgroup.com