2016-12-18 14 views
0

私はwordpressのプラグインを作っています。カスタムポストタイプがあります。このプラグインを新しいサイトにインストールすると、この新しいポストタイプの中に投稿が作成されます。 404エラー。もし私が設定 - > permalinks - >に行き、保存をクリックしてください。問題は修正されています。しかし、私はそれをmannualyしたいとは思わない私は私のプラグインが私のためにこれをしたい。だから、私はインターネットを見ていて、誰もが書き換え機能を使わなければならないと言っています。それは私のために働いていない...ここに私のコードです。wordpressプラグインのカスタムポストタイプエラー

<?php 

defined('ABSPATH') or die('No script kiddies please!'); 

// Creating the post type 

function eleva_sponsors_custom_post_type() { 

    $singular_sponsors = "Sponsor"; 

    $plural_sponsors = "Sponsors"; 

    $labels_sponsors = array(

      "name"     =>  $plural_sponsors, 
      "singular_name"   =>  $singular_sponsors, 
      "add_new"    =>  "Add New", 
      "add_new_item"   =>  "Add New " . $singular_sponsors, 
      "edit_item"    =>  "Edit " . $singular_sponsors, 
      "new_item"    =>  "New " . $singular_sponsors, 
      "view_item"    =>  "View " . $singular_sponsors, 
      "search_items"   =>  "Search " . $plural_sponsors, 
      "not_found"    =>  "No " . $plural_sponsors." found", 
      "not_found_in_trash" =>  "No " .$plural_sponsors." found in trash", 
      "all_items"    =>   "All sponsors" 
    ); 

    $args_sponsors = array(

      "labels"    =>   $labels_sponsors, 
      "public"    =>   true, 
      "publicity queryable" =>   true, 
      "show_in_nav_menus"  =>   true, 
      "show_ui"    =>   true, 
      "show_in_menu"   =>   true, 
      "show_in_admin_bar"  =>   true, 
      "menu_position"   =>   10, 
      "menu_icon"    =>   "dashicons-format-gallery", 
      "can_export"   =>   true, 
      "delete_with_user"  =>   false, 
      "hierarchical"   =>   false, 
      "has_archive"   =>   true, 
      "query_bar"    =>   true, 
      "capability_type"  =>   "post", 
      "map_meta_cap"   =>   true, 



      // capabilities => array() 

      "rewrite"    => array(

        "slug"    =>   "sponsors", 
        "whit_front"  =>   true, 
        "pages"    =>   true, 
        "feeds"    =>   true,  

       ), 
      "supports"    => array("title","thumbnail") 


    ); 

    register_post_type("sponsors",$args_sponsors); 
} 

add_action('init', 'eleva_sponsors_custom_post_type'); 

function custom_flush_rules(){ 
    //defines the post type so the rules can be flushed. 
    eleva_sponsors_custom_post_type(); 

    //and flush the rules. 
    flush_rewrite_rules(); 
} 

register_activation_hook(__FILE__, 'custom_flush_rules'); 


?> 

答えて

0

このコードを試してください。

function eleva_sponsors_custom_post_type() { 

     $singular_sponsors = "Sponsor1"; 

     $plural_sponsors = "Sponsors1"; 

     $labels_sponsors = array(

       "name"     =>  $plural_sponsors, 
       "singular_name"   =>  $singular_sponsors, 
       "add_new"    =>  "Add New", 
       "add_new_item"   =>  "Add New " . $singular_sponsors, 
       "edit_item"    =>  "Edit " . $singular_sponsors, 
       "new_item"    =>  "New " . $singular_sponsors, 
       "view_item"    =>  "View " . $singular_sponsors, 
       "search_items"   =>  "Search " . $plural_sponsors, 
       "not_found"    =>  "No " . $plural_sponsors." found", 
       "not_found_in_trash" =>  "No " .$plural_sponsors." found in trash", 
       "all_items"    =>   "All sponsors" 
     ); 

     $args_sponsors = array(

       "labels"    =>   $labels_sponsors, 
       "public"    =>   true, 
       "publicity queryable" =>   true, 
       "show_in_nav_menus"  =>   true, 
       "show_ui"    =>   true, 
       "show_in_menu"   =>   true, 
       "show_in_admin_bar"  =>   true, 
       "menu_position"   =>   10, 
       "menu_icon"    =>   "dashicons-format-gallery", 
       "can_export"   =>   true, 
       "delete_with_user"  =>   false, 
       "hierarchical"   =>   false, 
       "has_archive"   =>   false, 
       "query_bar"    =>   true, 
       "capability_type"  =>   "post", 
       "map_meta_cap"   =>   true, 



       // capabilities => array() 

       "rewrite"    => array(
        "slug"    =>   "sponsors", 
         "whit_front"  =>   true, 
         "pages"    =>   true, 
         "feeds"    =>   true,  

        ), 
       "supports"    => array("title","thumbnail") 


     ); 

     register_post_type("sponsors2",$args_sponsors); 
     flush_rewrite_rules(); 
    } 

    add_action('init', 'eleva_sponsors_custom_post_type'); 
関連する問題