Created
April 16, 2013 18:32
-
-
Save keithics/5398349 to your computer and use it in GitHub Desktop.
Get post by Slug - Wordpress
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
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; | |
} |
kmvan
commented
Jun 6, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment