-
-
Save prayas-sapkota/1773a1a16b12f788e3d9 to your computer and use it in GitHub Desktop.
This file contains 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_post_by_slug($post_name) { | |
global $wpdb; | |
$post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $post_name)); | |
return $post ? get_post($post) : NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment