Created
September 10, 2012 18:19
-
-
Save vc27/3692701 to your computer and use it in GitHub Desktop.
Get post_id from slug
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
/** | |
* 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