Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Created November 15, 2017 10:42
Show Gist options
  • Save BinaryMoon/885c50b21b3bf106d6acec19f8fc85d9 to your computer and use it in GitHub Desktop.
Save BinaryMoon/885c50b21b3bf106d6acec19f8fc85d9 to your computer and use it in GitHub Desktop.
An example function showing how to convert a WordPress category id to a slug.
<?php
function prefix_convert_category_id_to_slug( $value ) {
if ( is_int( $value ) ) {
$category = get_term( $value, 'category' );
if ( is_wp_error( $category ) ) {
return $value;
}
$value = $category->slug;
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment