在wordpress中取消设置一个posttype数组

时间:2013-01-21 12:08:23

标签: wordpress custom-post-type

我有一系列帖子,我显示它像贝娄

    $types = get_post_types( array(  
                                    'public' => true,
                                    '_builtin' => false), 'objects' ); 
    foreach ( $types as $type )
      echo '<li>'.'<a href="'.home_url().'/'.$type->name.'" id="'.$type->name.'">
      <span class="post-text">'. $type->singular_label.'</span>
      <span class="entry-title" style="display:none;">'.$type->description.'</span>
      </a></li>';

我必须从上面的数组中取消数组中的数组,意味着

    [news] => stdClass Object
        (
            [labels] => stdClass Object
                (
                    [name] => News
                    [singular_name] => News
                    [add_new] => Add News
                    [add_new_item] => Add New News
                    [edit_item] => Edit News
                    [new_item] => New News
                    [view_item] => View News
                    [search_items] => Search News
                    [not_found] => No News Found
                    [not_found_in_trash] => No News Found in Trash
                    [parent_item_colon] => Parent Page:
                    [all_items] => News
                    [menu_name] => News
                    [edit] => Edit
                    [view] => View News
                    [parent] => Parent News
                    [name_admin_bar] => News
                )

            [description] => This will display all the posts under news post type.
            [publicly_queryable] => 1
            [exclude_from_search] => 
            [capability_type] => post
            [map_meta_cap] => 1
            [_builtin] => 
            [_edit_link] => post.php?post=%d
            [hierarchical] => 1
            [public] => 1
            [rewrite] => Array
                (
                    [slug] => news
                    [with_front] => 1
                    [pages] => 1
                    [feeds] => 1
                    [ep_mask] => 1
                )

            [has_archive] => 1
            [query_var] => news
            [register_meta_box_cb] => 
            [taxonomies] => Array
                (
                    [0] => category
                )

            [show_ui] => 1
            [menu_position] => 
            [menu_icon] => 
            [can_export] => 1
            [show_in_nav_menus] => 1
            [show_in_menu] => 1
            [show_in_admin_bar] => 1
            [delete_with_user] => 
            [label] => News
            [singular_label] => News
            [name] => news
            [cap] => stdClass Object
                (
                    [edit_post] => edit_post
                    [read_post] => read_post
                    [delete_post] => delete_post
                    [edit_posts] => edit_posts
                    [edit_others_posts] => edit_others_posts
                    [publish_posts] => publish_posts
                    [read_private_posts] => read_private_posts
                    [read] => read
                    [delete_posts] => delete_posts
                    [delete_private_posts] => delete_private_posts
                    [delete_published_posts] => delete_published_posts
                    [delete_others_posts] => delete_others_posts
                    [edit_private_posts] => edit_private_posts
                    [edit_published_posts] => edit_published_posts
                )

        )

    [wardrobes] => stdClass Object
        (
            [labels] => stdClass Object
                (
                    [name] => Wardrobes
                    [singular_name] => Wardrobes
                    [add_new] => Add Wardrobes
                    [add_new_item] => Add New Wardrobes
                    [edit_item] => Edit Wardrobes
                    [new_item] => New Wardrobes
                    [view_item] => View Wardrobes
                    [search_items] => Search Wardrobes
                    [not_found] => No Wardrobes Found
                    [not_found_in_trash] => No Wardrobes Found in Trash
                    [parent_item_colon] => Parent Page:
                    [all_items] => Wardrobes
                    [menu_name] => Wardrobes
                    [edit] => Edit
                    [view] => View Wardrobes
                    [parent] => Parent Wardrobes
                    [name_admin_bar] => Wardrobes
                )

            [description] => This will show all the posts under Wardrobes post type.
            [publicly_queryable] => 1
            [exclude_from_search] => 1
            [capability_type] => post
            [map_meta_cap] => 1
            [_builtin] => 
            [_edit_link] => post.php?post=%d
            [hierarchical] => 1
            [public] => 1
            [rewrite] => Array
                (
                    [slug] => wardrobes
                    [with_front] => 1
                    [pages] => 1
                    [feeds] => 1
                    [ep_mask] => 1
                )

            [has_archive] => 1
            [query_var] => wardrobes
            [register_meta_box_cb] => 
            [taxonomies] => Array
                (
                    [0] => category
                )

            [show_ui] => 1
            [menu_position] => 
            [menu_icon] => 
            [can_export] => 1
            [show_in_nav_menus] => 1
            [show_in_menu] => 1
            [show_in_admin_bar] => 1
            [delete_with_user] => 
            [label] => Wardrobes
            [singular_label] => Wardrobes
            [name] => wardrobes
            [cap] => stdClass Object
                (
                    [edit_post] => edit_post
                    [read_post] => read_post
                    [delete_post] => delete_post
                    [edit_posts] => edit_posts
                    [edit_others_posts] => edit_others_posts
                    [publish_posts] => publish_posts
                    [read_private_posts] => read_private_posts
                    [read] => read
                    [delete_posts] => delete_posts
                    [delete_private_posts] => delete_private_posts
                    [delete_published_posts] => delete_published_posts
                    [delete_others_posts] => delete_others_posts
                    [edit_private_posts] => edit_private_posts
                    [edit_published_posts] => edit_published_posts
                )

        )

    [journal] => stdClass Object
        (
            [labels] => stdClass Object
                (
                    [name] => Journal
                    [singular_name] => Journal==
                    [add_new] => Add Journal==
                    [add_new_item] => Add New Journal==
                    [edit_item] => Edit Journal==
                    [new_item] => New Journal==
                    [view_item] => View Journal==
                    [search_items] => Search Journal
                    [not_found] => No Journal Found
                    [not_found_in_trash] => No Journal Found in Trash
                    [parent_item_colon] => Parent Page:
                    [all_items] => Journal
                    [menu_name] => Journal
                    [edit] => Edit
                    [view] => View Journal==
                    [parent] => Parent Journal==
                    [name_admin_bar] => Journal==
                )

            [description] => This will show all the posts under journal post type.
            [publicly_queryable] => 1
            [exclude_from_search] => 
            [capability_type] => post
            [map_meta_cap] => 1
            [_builtin] => 
            [_edit_link] => post.php?post=%d
            [hierarchical] => 1
            [public] => 1
            [rewrite] => Array
                (
                    [slug] => journal
                    [with_front] => 1
                    [pages] => 1
                    [feeds] => 1
                    [ep_mask] => 1
                )

            [has_archive] => 1
            [query_var] => journal
            [register_meta_box_cb] => 
            [taxonomies] => Array
                (
                    [0] => category
                    [1] => post_tag
                )

            [show_ui] => 1
            [menu_position] => 
            [menu_icon] => 
            [can_export] => 1
            [show_in_nav_menus] => 1
            [show_in_menu] => 1
            [show_in_admin_bar] => 1
            [delete_with_user] => 
            [label] => Journal
            [singular_label] => Journal==
            [name] => journal
            [cap] => stdClass Object
                (
                    [edit_post] => edit_post
                    [read_post] => read_post
                    [delete_post] => delete_post
                    [edit_posts] => edit_posts
                    [edit_others_posts] => edit_others_posts
                    [publish_posts] => publish_posts
                    [read_private_posts] => read_private_posts
                    [read] => read
                    [delete_posts] => delete_posts
                    [delete_private_posts] => delete_private_posts
                    [delete_published_posts] => delete_published_posts
                    [delete_others_posts] => delete_others_posts
                    [edit_private_posts] => edit_private_posts
                    [edit_published_posts] => edit_published_posts
                )

        )

)

现在,当我得到自定义的帖子类型数组时,我必须从数组中删除“衣柜”。

在wordpress或php中是否有任何功能。请帮帮我。

1 个答案:

答案 0 :(得分:1)

如果你用Google搜索php + unset,你就会发现:

  

unset — Unset a given variable

     

unset()销毁指定的变量   函数内部 unset()的行为可能会有所不同,具体取决于您尝试销毁的变量类型。

在您的示例中:unset( $types['wardrobes'] );