Created
June 15, 2013 03:43
-
-
Save micahblu/5786794 to your computer and use it in GitHub Desktop.
a wordpress function that allows you to grab a page or custom post type by its slug. Originally from Matheus Eduardo http://wordpress.stackexchange.com/users/3575/matheus-eduardo
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_page_by_slug($page_slug, $output = OBJECT, $post_type = 'page' ) { | |
global $wpdb; | |
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $page_slug, $post_type ) ); | |
if ( $page ) | |
return get_page($page, $output); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment