Skip to content

Instantly share code, notes, and snippets.

@waelio
Last active December 29, 2015 13:15
Show Gist options
  • Save waelio/9a270d4ee6bbd5d12bcd to your computer and use it in GitHub Desktop.
Save waelio/9a270d4ee6bbd5d12bcd to your computer and use it in GitHub Desktop.
WP- Return the object type
<?php
/**
* @param object|int|string $object
* @return string
*/
function get_object_type($object){
$workable = false;
$object_type = gettype($object);
switch($object_type){
case 'object':
$workable=true;
break;
case 'string':
$workable = (is_numeric(intval(trim($object))));
break;
case 'integer':
$workable =true;
break;
}
if($workable){
if ($object_type == 'object'){
return (isset($object->post_type)) ? $object->post_type : $object->taxonomy;
}else{
$test = get_post($object);
if (is_object($test))
return get_object_type($test);
else
return get_object_type(get_category($object));
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment