Wordpress默认博客和自定义帖子分类路径问题

Wordpress默认博客和自定义帖子分类路径问题,wordpress,categories,custom-post-type,permalinks,custom-taxonomy,Wordpress,Categories,Custom Post Type,Permalinks,Custom Taxonomy,我好像碰到了一堵墙。我们正在建立一个新的wordpress网站,永久链接的结构是“/labs/%postname%/”。这适用于所有帖子,使用/labs/作为基础。我们的问题是,我们需要为我们的公文包定制一个帖子类型,其中我的基本url应该是/work,然后可能是/work/digital、/work/cgi等等。我还创建了自定义帖子类型和分类法,但不管我做什么,我所有自定义帖子的url都以/labs/开头 我尝试了大量的建议,从重写规则到更改register\u分类函数中的rewrite参数。

我好像碰到了一堵墙。我们正在建立一个新的wordpress网站,永久链接的结构是“/labs/%postname%/”。这适用于所有帖子,使用/labs/作为基础。我们的问题是,我们需要为我们的公文包定制一个帖子类型,其中我的基本url应该是/work,然后可能是/work/digital、/work/cgi等等。我还创建了自定义帖子类型和分类法,但不管我做什么,我所有自定义帖子的url都以/labs/开头

我尝试了大量的建议,从重写规则到更改register\u分类函数中的rewrite参数。我使用的代码如下:

function create_post_type() {
register_post_type( 'our_work',
    array(
        'labels' => array(
            'name' => __( 'Work Items' ),
            'singular_name' => __( 'Work Item' )
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'work'),
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'custom-fields',
            'revisions',
            'thumbnail',
            'page-attributes'   
        ),
    )
);
}
add_action( 'init', 'create_post_type' );

function create_taxonomies() {
register_taxonomy('work-categories', array('our_work'), array(
    'labels' => array(
        'name' => 'Work Categories'
    ),
    'show_ui' => true,
    'show_tagcloud' => false,
    'rewrite' => true,
    'hierarchical' => true,
    'with_front' => false
));
}
add_action('init', 'create_taxonomies');
已尝试将“重写”参数更改为true、false、hierarchical,甚至将其替换为自定义帖子类型的名称

甚至有可能做到这一点吗?我们在这里要做的就是让博客和自定义帖子位于两个不同的基本路径下,我想这很容易做到

很抱歉,如果之前已经讨论过这一点,那么术语就混淆了,搜索结果会显示与此相关的任何内容


谢谢

我似乎总是在这里发布几分钟后找到自己的解决方案。。。接下来,对于有相同问题的人,请确保自定义帖子类型的注册和分类中的slug都是相同的。。。还要确保你使用发电机,因为它很容易错过一些东西。。。所以现在我两个基地都正常工作了,一点问题也没有!:)

编辑:所以,无论您在常规设置中使用什么基,都将适用于所有正常的帖子,但通过添加的功能和正确的绑定,所有自定义的帖子都将被重写。希望这有帮助

<?php 

/**
 * Register Custom Post Type
*/
function create_post_type() {
register_post_type( 'our_work', array(
        'label'              => 'Work Items',
        'singular_label'     => 'Work Item',
        'description'        => 'Our work items',
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'query_var'          => true,
        'has_archive'        => true,
        'hierarchical'       => true,
        'supports'           => array( 'title', 'editor', 'excerpt', 'custom-fields', 'revisions', 'thumbnail', 'page-attributes' ),
        'rewrite'            => array( 'slug' => 'work-items/%work-categories%', 'with_front' => false),
    )
);
}
add_action( 'init', 'create_post_type' );

/**
 * Register Custom Taxonomy
*/
function create_taxonomies() {
$labels = array(
    'name'                       => 'work-categories',
    'singular_name'              => 'work-category',
    'menu_name'                  => 'Work Categories',
    'all_items'                  => 'All Items',
    'parent_item'                => 'Parent Item',
    'parent_item_colon'          => 'Parent Item:',
    'new_item_name'              => 'New Item Name',
    'add_new_item'               => 'Add New Item',
    'edit_item'                  => 'Edit Item',
    'update_item'                => 'Update Item',
    'separate_items_with_commas' => 'Separate items with commas',
    'search_items'               => 'Search Items',
    'add_or_remove_items'        => 'Add or remove items',
    'choose_from_most_used'      => 'Choose from the most used items',
    'not_found'                  => 'Not Found',
);
$rewrite = array(
    'slug'                       => 'work-items',
    'with_front'                 => false,
    'hierarchical'               => true,
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => false,
    'show_tagcloud'              => false,
    'rewrite'                    => $rewrite,
    'query_var'                  => 'work-categories',
);
register_taxonomy( 'work-categories', 'our_work', $args );
}
add_action('init', 'create_taxonomies');


/**
 * Add custom filters to replace categories in custom taxonomy paths
*/
add_filter('post_link', 'brand_permalink', 1, 3);
add_filter('post_type_link', 'brand_permalink', 1, 3);

function brand_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%work-categories%') === FALSE) return $permalink;

// Get post
$post = get_post($post_id);
if (!$post) return $permalink;

// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'work-categories');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
    $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'uncategorised';

return str_replace('%work-categories%', $taxonomy_slug, $permalink);
}

?>


同样的问题,使用自定义帖子类型用户界面,您能详细说明您的解决方案吗?只需为每个人添加代码,很抱歉耽搁太久!