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
                )

        )

)

カスタム投稿タイプの配列を取得したら、配列から「ワードローブ」を削除する必要があります。

ワードプレスやPHPに機能はありますか?私を助けてください。

4

1 に答える 1

1

あなたがグーグルphp+を持っていたならunset、あなたは見つけたでしょう:

unset —指定された変数の設定を解除します

unset()は、指定された変数を破棄します。関数内のunset()
の動作は、破棄しようとしている変数のタイプによって異なります。

あなたの例では:unset( $types['wardrobes'] );

于 2013-01-22T04:24:58.463 に答える