2017-01-23 4 views
0

私はpost_parentのIDをチェックして、メタページの選択メニューに子ページを追加するといういくつかの引数を持っています。Get_Postsでslugを使う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, 
      ), 
     ), 

あなたはget_page_by_path()を使用して、ご希望のスラグのポストIDを取得し、その後、引数に結果を渡すことができhttps://codex.wordpress.org/Template_Tags/get_posts

答えて

1

と同じ引数を使用します。例:

$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はポストが作成された後も一定のままです。

関連する問題