Skip to content

Instantly share code, notes, and snippets.

@micahblu
Created June 15, 2013 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save micahblu/5786794 to your computer and use it in GitHub Desktop.
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
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