首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义post类型、permalinks和数字

自定义post类型、permalinks和数字
EN

Stack Overflow用户
提问于 2015-05-19 18:27:44
回答 1查看 56关注 0票数 0

这是给猫收容所用的。我有一个定制的帖子类型,叫做“猫”。

然后,我对可用性进行了分类,包括"available“和"homed”。

一切都很好..。直到有重复的猫的名字。例如,如果Milo在一个月内来,那么一年后,另一个Milo来了。显然,WordPress将创建siteurl/cat/milo/,然后为第二个站点创建siteurl/cat/milo-2/。

原版米洛工作得很好。一旦输入这个数字,milo-2就无法工作,并重定向到404。

自定义邮政

代码语言:javascript
复制
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 );

}

分类学

代码语言:javascript
复制
// 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 );

我们认为这可能是数据库里的冲突.尝试重新保存permalinks,删除未使用的DB条目,禁用所有插件.没什么。

手动将cat重命名为,比方说,milo_工作得很好,但是它中的任何数字都只会发送回我的404。

使用Starkers响应主题,没有子主题。标准htaccess。

我是不是错过了一些显而易见的东西?

在这里找到一只有数字的猫.http://catsnottingham.zellement.com/cats/homed/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-22 14:14:28

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

我觉得用“猫”作为CPT可能和分类有冲突.不知何故。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30333355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档