답변:
당신은 사용할 수 있습니다 get_page_by_path()-이름이 당신을 바보하게하지 마십시오, 세 번째 인수는 게시물 유형입니다 :
if ( $post = get_page_by_path( 'the_slug', OBJECT, 'post_type' ) )
$id = $post->ID;
else
$id = 0;
며칠 기다렸다가 12 월 8 일 ( AFAIK )에 릴리스 될 Wordpress 4.4로 업그레이드 하는 경우 슬러그 배열을 취하는 새로운 매개 변수를 사용할 수 있습니다post_name__inWP_Query
완전한 포스트 오브젝트가 필요한 경우
$args = [
'post_type' => 'my_custom_post_type',
'posts_per_page' => 1,
'post_name__in' => ['post-slug']
];
$q = get_posts( $args );
var_dump( $q );
ID 만 필요한 경우
$args = [
'post_type' => 'my_custom_post_type',
'posts_per_page' => 1,
'post_name__in' => ['post-slug'],
'fields' => 'ids'
];
$q = get_posts( $args );
var_dump( $q );
post_name재산 및 category_name했어야 매개 변수, slug하지와name