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; | |
} |
\get_page_by_path( 'sulg', \OBJECT, 'post');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And why don't you use native get_page_by_path function?
https://codex.wordpress.org/Function_Reference/get_page_by_path