Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get post id by title
/**
* Get id from post title
*
* @version 0.01
* @access internal
* @author Agavriloaie Marius <contact@dexblog.ro>
*
* @param none
* @return none
* =====================================================================================================
*
* =====================================================================================================
*/
function get_post_by_title($page_title, $type = "post", $output = OBJECT) {
global $wpdb;
$post = $wpdb->get_var ( $wpdb->prepare ( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='$type'", $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