Skip to content

Instantly share code, notes, and snippets.

@Robzelf
Last active May 20, 2021 13:25
Show Gist options
  • Save Robzelf/51da9fe1d41583f0188e2f5f6448a994 to your computer and use it in GitHub Desktop.
Save Robzelf/51da9fe1d41583f0188e2f5f6448a994 to your computer and use it in GitHub Desktop.
function get_cat( $_slug ) {
$_categories = get_terms( 'category', array( 'hide_empty' => false, 'order' => 'ASC' ) );
$_result = array_values( array_filter( $_categories, function($obj){
if (isset($obj->slug)) {
if( $obj->slug == [needle] ):
$_term_id = $obj->term_id;
return true;
endif;
}
}));
return $_result[0]->term_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment