static function get_post_by($by, $value, $args = array())
{
$_post = null;
$criteria = array('post_status' => 'publish');
switch ($by) {
case 'slug':
case 'post_name':
$criteria['name'] = trim($value);
break;
case 'post_id':
case 'post_ID':
case 'id':
case 'ID':
$criteria['p'] = intval($value);
break;
}
$query = new WP_Query(wp_parse_args($args, $criteria));
if (count($query->posts)) {
$_post = $query->post;
}
return $_post;
}