2017-01-23 5 views
0

나는 metabols의 선택 메뉴에 하위 페이지를 추가하기 위해 post_parent ID를 확인하는 몇 가지 인수가 있습니다.Get_Posts에서 슬러그를 사용하는 Post_Parent 가져 오기 args

그러나 나는 페이지의 ID를 사용하지 않을 것이지만 변경 될 수는 있지만 슬러그는 항상 동일합니다.

 // POST 
     array(
      'name'  => esc_html__('Select the previous page for the button link', 'uhd'), 
      'id'   => "{$prefix}prev_target", 
      'type'  => 'post', 
      // Post type 
      'post_type' => 'page', 
      // Field type, either 'select' or 'select_advanced' (default) 
      'field_type' => 'select_advanced', 
      'placeholder' => esc_html__('Select an Item', 'uhd'), 
      // Query arguments (optional). No settings means get all published posts 
      'query_args' => array(
       'post_status' => 'publish', 
       'posts_per_page' => - 1, 
       'post_parent' => 18, 
      ), 
     ), 

https://codex.wordpress.org/Template_Tags/get_posts

답변

1

당신은 get_page_by_path()를 사용하여 원하는 슬러그의 게시물 ID를 얻을 수있는 동일한 인수를 사용하고 인수에 결과를 전달합니다. 예 :

$parent_post = get_page_by_path('full/slug'); 

$args = array(
    [...] 
    'query_args' => array(
     'post_parent' => $parent_post->ID, 
    ), 
); 

이 당신이뿐만 아니라에서 그 통과해야합니다 사용자 정의 포스트 유형 인 경우 :

$parent_post = get_page_by_path('full/slug', OBJECT, 'post-type'); 

이 일반적 게시물의 슬러그 변경할 수있는 일이 말했다 모든 ID가 아닌 어쩌면 고유 한 사용 시나리오가있을 수 있지만 사용자가 편집 할 수있는 플러그인 (또는 플러그인 편집 가능) 인 반면 게시 ID는 게시가 생성 된 후에도 일정하게 유지됩니다.