Created
March 6, 2014 15:48
-
-
Save Dexterstat/9392618 to your computer and use it in GitHub Desktop.
Get post id by title
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
/** | |
* 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