Created
May 19, 2017 15:43
-
-
Save lukecav/5b8c7e1027019e74686fa5bc983af7cb to your computer and use it in GitHub Desktop.
Get Post by Title in WordPress
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_title($page_title, $output = OBJECT) { | |
global $wpdb; | |
$post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title )); | |
if ( $post ) | |
return get_post($post, $output); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment