WordPress ||自定义帖子类型,永久链接&数字

时间:2015-05-19 18:27:45

标签: php wordpress permalinks

这是一个猫庇护所。我有一个自定义的帖子类型,名为" cat"。

然后,我对可用性进行了分类,并提供了"可用"和"归乡"。

一切正常......直到猫的名字重复。例如,如果Milo进入一个月,那么一年后,另一个Milo进来。显然,WordPress将创建 siteurl / cat / milo / ,然后在第二个时间创建 siteurl /猫/蜀黍-2 /

原来Milo工作得很好......一旦输入数字,milo-2就无法工作,并重定向到404.

自定义帖子类型

function cat_post_type() {

    $labels = array(
        'name'                => _x( 'Cats', 'Post Type General Name', 'text_domain' ),
        'singular_name'       => _x( 'Cat', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'           => __( 'Cats', 'text_domain' ),
        'name_admin_bar'      => __( 'Cats', 'text_domain' ),
        'parent_item_colon'   => __( 'Parent Cat:', 'text_domain' ),
        'all_items'           => __( 'All Cats', 'text_domain' ),
        'add_new_item'        => __( 'Add Cat', 'text_domain' ),
        'add_new'             => __( 'New Cat', 'text_domain' ),
        'new_item'            => __( 'New Cat', 'text_domain' ),
        'edit_item'           => __( 'Edit Cat', 'text_domain' ),
        'update_item'         => __( 'Update Cat', 'text_domain' ),
        'view_item'           => __( 'View Cat', 'text_domain' ),
        'search_items'        => __( 'Search cats', 'text_domain' ),
        'not_found'           => __( 'No cats found', 'text_domain' ),
        'not_found_in_trash'  => __( 'No cats found in Trash', 'text_domain' ),
    );
    $args = array(
        'label'               => __( 'cats', 'text_domain' ),
        'description'         => __( 'All cats', 'text_domain' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'thumbnail', 'comments'),
        'taxonomies'          => array( 'available', 'homed' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'menu_position'       => 5,
        'menu_icon'           => 'dashicons-smiley',
        'show_in_admin_bar'   => true,
        'show_in_nav_menus'   => true,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
    );
    register_post_type( 'cat', $args );

}

分类

// Hook into the 'init' action
add_action( 'init', 'cat_post_type', 0 );


    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('availability', 'cat', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Cats Availability', 'taxonomy general name' ),
          'singular_name' => _x( 'Cat Availability', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Cat Availability' ),
          'all_items' => __( 'All Availability' ),
          'parent_item' => __( 'Parent Availability' ),
          'parent_item_colon' => __( 'Parent Availability:' ),
          'edit_item' => __( 'Edit Availability' ),
          'update_item' => __( 'Update Availability' ),
          'add_new_item' => __( 'Add New Availability' ),
          'new_item_name' => __( 'New Availability' ),
          'menu_name' => __( 'Availability' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'cats', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );

我们认为这可能是数据库冲突的问题...尝试重新保存固定链接,删除未使用的数据库条目,禁用所有插件......没有。

手动将猫重命名为,例如,milo_可以正常工作,但是其中的任何数字都会发回我的404.

使用Starkers响应主题,没有儿童主题。标准的htaccess。

我错过了一些明显的东西吗?

此处未完成的网站 - 在其链接中找到一个带有数字的猫...... http://catsnottingham.zellement.com/cats/homed/

1 个答案:

答案 0 :(得分:0)

我已修复此问题 - 我认为它一定是数据库冲突,损坏或错误,所以我重新开始使用新的WordPress安装,这已经解决了问题。

部分我认为使用“猫”作为CPT可能会与类别发生冲突......不知何故。

相关问题