函数
wp_get_associated_nav_menu_items ( $object_id = 0, $object_type = 'post_type', $taxonomy = '' )
- 参数
-
-
(int)
$object_id
Optional. The ID of the original object. Default 0.- Required: 否
-
(string)
$object_type
Optional. The type of object, such as ‘post_type’ or ‘taxonomy’. Default ‘post_type’.- Required: 否
- Default: ‘post_type’
-
(string)
$taxonomy
Optional. If $object_type is ‘taxonomy’, $taxonomy is the name of the tax that $object_id belongs to. Default empty.- Required: 否
- Default: (empty)
-
(int)
- 返回值
-
- (int[]) The array of menu item IDs; empty array if none.
- 定义位置
-
-
wp-includes/nav-menu.php
, line 1009
-
wp-includes/nav-menu.php
- 引入
- 3.0.0
- 弃用
- –
返回与一个特定对象相关的菜单项。
function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) { $object_id = (int) $object_id; $menu_item_ids = array(); $query = new WP_Query; $menu_items = $query->query( array( 'meta_key' => '_menu_item_object_id', 'meta_value' => $object_id, 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'posts_per_page' => -1, ) ); foreach ( (array) $menu_items as $menu_item ) { if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { $menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); if ( 'post_type' === $object_type && 'post_type' === $menu_item_type ) { $menu_item_ids[] = (int) $menu_item->ID; } elseif ( 'taxonomy' === $object_type && 'taxonomy' === $menu_item_type && get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy ) { $menu_item_ids[] = (int) $menu_item->ID; } } } return array_unique( $menu_item_ids ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。