You can use get_page_by_path()
– don’t let the name fool you, third argument is the post type:
1 2 3 4 |
if ( $post = get_page_by_path( 'the_slug', OBJECT, 'post_type' ) ) $id = $post->ID; else $id = 0; |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.