Skip to content

Instantly share code, notes, and snippets.

@Dexterstat
Created March 6, 2014 15:48
Show Gist options
  • Save Dexterstat/9392618 to your computer and use it in GitHub Desktop.
Save Dexterstat/9392618 to your computer and use it in GitHub Desktop.
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