0

我有一系列帖子,我将其显示如下

    $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.ini 中是否有任何功能?请帮我。

4

1 回答 1

1

如果你用 google 搜索过php+ unset,你会发现:

unset - 取消设置给定变量

unset()销毁指定的变量。函数内部unset()
的行为可能因您尝试销毁的变量类型而异。

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

于 2013-01-22T04:24:58.463 回答