dw90000
11/11/2016 - 3:54 AM

カテゴリーを取得

カテゴリーを取得

	$cats = get_the_category();

	foreach ( $cats as $cat ) {
	  $cat_ID          = $cat -> cat_ID;
	  $cat_name        = $cat -> cat_name;
	  $cat_nicename    = $cat -> category_nicename;
	  $cat_description = $cat -> category_description;
	  $category_parent = $cat -> category_parent;
	  $cat_slug        = $cat -> cat_slug;

	  if($category_parent != 0){
	  	$now_cat = $cat_name;
	  	$now_id = $cat_ID;
	  	$now_slug = $cat_nicename;
	  }else{
	  	$cat_parent = $cat_name;
	  	$cat_parent_id = $cat_ID;
	  	$cat_parent_slug = $cat_nicename;
	  }
	}
$terms = get_terms( 'category' );
if ( ! empty( $terms ) && !is_wp_error( $terms ) ){
    foreach ( $terms as $term ) {
        if($term->name == "news"){
            $termID =  $term->term_id;
            break;
        }
    }
}