get_ancestors

Sponsored Link

指定されたオブジェクトの親を含む配列を返します。

Sponsored Link

Returns an array containing the parents of the given object.

get_ancestorsのファンクションタグ使用方法

<?php get_ancestors( $object_id, $object_type ); ?>

デフォルトの使用方法

 <?php get_ancestors(
    'object_id'   => 6, 
    'object_type'  => 'page' ); ?> 

get_ancestorsのパラメーター

$object_id

(int or string) (required) 子オブジェクトのID
デフォルト:なし

(int or string) (required) The ID of the child object
Default: None

$object_type

(string) (required)問題のオブジェクト·タイプ(ページ、カテゴリ)の名前
デフォルト:なし

(string) (required) The name of the object type (page, category) in question
Default: None

戻り値

(array)階層内の最下位から最上位への祖先の配列

(array)
Array of ancestors from lowest to highest in the hierarchy

次のカテゴリ階層(ID付き)を取得する:

Given the following category hierarchy (with IDs):

  • Books (6)
    • Fiction (23)
      • Mystery (208)
<?php get_ancestors( 208, 'category' ); ?>

返し:

 Array
(
    [0] => 23
    [1] => 6
) 

次のページ階層(ID付き)を取得する:

Given the a page hierarchy (with IDs):

  • About (447)
    • Child Page (448)
<?php get_ancestors( 448, 'page' ); ?>

返し:

  Array
(
    [0] => 447
) 

注意

フィルター:それが返される前にget_ancestorsは祖先配列に適用されます。

Filter: get_ancestors is applied to ancestors array before it is returned.

変更ログ

Since: 3.1.0

ソースファイル

get_ancestors()は、wp-includes/taxonomy.php内に位置しています。

get_ancestors() is located in wp-includes/taxonomy.php.

関連ファンクションタグ

Page Tags: get_all_page_ids(), get_ancestors(), get_page(), get_page_link(), get_page_by_path(), get_page_by_title(), get_page_children(), get_page_hierarchy(), get_page_uri(), get_pages(), is_page(), page_uri_index(), wp_list_pages(), wp_page_menu()

Sponsored Link