Skip to content

Instantly share code, notes, and snippets.

@vc27
Created September 10, 2012 18:19
Show Gist options
  • Save vc27/3692701 to your computer and use it in GitHub Desktop.
Save vc27/3692701 to your computer and use it in GitHub Desktop.
Get post_id from slug
/**
* Get post_id from slug
*
* @version 0.1
* @updated 09.10.12
*
**/
function get_post_id_by_slug( $slug ) {
global $wpdb;
$querystr = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_name = '$slug' LIMIT 1";
$results = $wpdb->get_results( $querystr );
if ( isset( $results[0]->ID ) AND is_numeric( $results[0]->ID ) )
return $results[0]->ID;
else
return false;
} // end function get_post_id_by_slug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment