Created
June 17, 2014 15:04
-
-
Save DanBeckett/e307c43b201646ccf9b9 to your computer and use it in GitHub Desktop.
Quick function to convert a permalink into a term object when inside a custom taxonomy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_term_object_from_uri($taxonomy) { | |
global $wp; | |
//get requested uri | |
$wp_request = $wp->request; | |
//split into array | |
$uri_params = explode('/', $wp_request); | |
//drop the product id as unnecessary | |
$param_total = (count($uri_params)-1); | |
unset($uri_params[$param_total]); | |
//get the new deepest level category | |
$param_top_level = $param_total-1; | |
$param_slug = $uri_params[$param_top_level]; | |
$param_object = get_term_by( 'slug', $param_slug, $taxonomy ); | |
return $param_object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment