wordpress寄存器post类型重写规则不';行不通
第一类员额:wordpress寄存器post类型重写规则不';行不通,post,url-rewriting,custom-post-type,Post,Url Rewriting,Custom Post Type,第一类员额: add_action( 'init', 'create_pressrelease' ); function create_pressrelease() { register_post_type( 'pressreleases', array( 'labels' => array( 'name' => __( 'Press Releases' ), 'sin
add_action( 'init', 'create_pressrelease' );
function create_pressrelease() {
register_post_type( 'pressreleases',
array(
'labels' => array(
'name' => __( 'Press Releases' ),
'singular_name' => __( 'Press Release' )
),
'has_archive' => true,
'show_in_menu' => 'edit.php?post_type=storefronts',
'public' => true,
'map_meta_cap' => true,
'menu_position' => 4,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-edit',
'has_archive' => 'pressreleases',
'with_front' => false,
'rewrite' => array(
'slug' => 'suppliers/%supplier_name%/pressreleases',
)
)
);
}
add_action( 'init', 'create_whitepaper' );
function create_whitepaper() {
register_post_type( 'whitepapers',
array(
'labels' => array(
'name' => __( 'White Papers' ),
'singular_name' => __( 'White Paper' )
),
'has_archive' => true,
'show_in_menu' => 'edit.php?post_type=storefronts',
'public' => true,
'map_meta_cap' => true,
'menu_position' => 4,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-edit',
'has_archive' => 'whitepapers',
'rewrite' => array(
'slug' => 'suppliers/%supplier_name%/whitepapers',
)
)
);
}
第二类员额:
add_action( 'init', 'create_pressrelease' );
function create_pressrelease() {
register_post_type( 'pressreleases',
array(
'labels' => array(
'name' => __( 'Press Releases' ),
'singular_name' => __( 'Press Release' )
),
'has_archive' => true,
'show_in_menu' => 'edit.php?post_type=storefronts',
'public' => true,
'map_meta_cap' => true,
'menu_position' => 4,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-edit',
'has_archive' => 'pressreleases',
'with_front' => false,
'rewrite' => array(
'slug' => 'suppliers/%supplier_name%/pressreleases',
)
)
);
}
add_action( 'init', 'create_whitepaper' );
function create_whitepaper() {
register_post_type( 'whitepapers',
array(
'labels' => array(
'name' => __( 'White Papers' ),
'singular_name' => __( 'White Paper' )
),
'has_archive' => true,
'show_in_menu' => 'edit.php?post_type=storefronts',
'public' => true,
'map_meta_cap' => true,
'menu_position' => 4,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-edit',
'has_archive' => 'whitepapers',
'rewrite' => array(
'slug' => 'suppliers/%supplier_name%/whitepapers',
)
)
);
}
我已经创建了以上两种帖子类型,我能够获得第一种帖子类型的正确页面,第二种帖子类型的正确页面,我得到了URL,但加载了主页内容,为什么会发生这种情况?这两种代码中是否有我遗漏的内容。建议我两天以来一直尝试各种方法,如添加\ u重写,perma_结构,需要一些解决方案添加刷新重写规则(false);在该寄存器后输入('straws',$args) 据我所知,你得到了错误的帖子链接,这是它造成的 “重写”=>数组( “slug”=>“供应商/%supplier\u name%/新闻稿”, )
您只需删除两个“rewrite”参数并设置永久链接。在您的情况下,在函数register\u post\u type(‘白皮书’,…)之后添加刷新重写规则;看看: