Skip to content

Instantly share code, notes, and snippets.

@paulvanbuuren
Last active September 26, 2018 13:17
Show Gist options
  • Save paulvanbuuren/6d9f10da72abe560e3117e6b05d620ab to your computer and use it in GitHub Desktop.
Save paulvanbuuren/6d9f10da72abe560e3117e6b05d620ab to your computer and use it in GitHub Desktop.
/**
* 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