Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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