Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Retrieve a post ID for a slug and post type
*/
function get_postid_by_slug( $page_slug = '', $posttype = 'post' ) {
if ( $page_slug ) {
$postobject = get_page_by_path( $page_slug, OBJECT, $posttype );
if ( $postobject ) {
return $postobject->ID;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment