admin管理员组

文章数量:1313107

I'm trying to change the URL for my custom post type archive.

At the moment, the archive of my post type has the URL /

I want to change that to /

First I tried to just get it to display /, but that doesn't even work. I thought the rewrite parameter would do this when I register the custom post type.

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'menu_position' => 6,
    'menu_icon' => 'dashicons-list-view',
    'show_in_rest' => true,
    'rewrite' => array('slug' => 'somethingelse'),
    'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpts', 'revisions', 'custom-fields'),
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'has_archive' => 'myposttype'
);

But the rewrite doesn't seem to do anything. I refreshed the permalinks and went to /, but the page can't be found. Why doesn't it do, what I want?

I'm trying to change the URL for my custom post type archive.

At the moment, the archive of my post type has the URL https://example/myposttype/

I want to change that to https://example/xyz/somethingelse/

First I tried to just get it to display https://example/somethingelse/, but that doesn't even work. I thought the rewrite parameter would do this when I register the custom post type.

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'menu_position' => 6,
    'menu_icon' => 'dashicons-list-view',
    'show_in_rest' => true,
    'rewrite' => array('slug' => 'somethingelse'),
    'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpts', 'revisions', 'custom-fields'),
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'has_archive' => 'myposttype'
);

But the rewrite doesn't seem to do anything. I refreshed the permalinks and went to https://example/somethingelse/, but the page can't be found. Why doesn't it do, what I want?

Share Improve this question edited Dec 8, 2020 at 12:20 Ashish Odich 1035 bronze badges asked Dec 8, 2020 at 11:20 TheKidsWantDjentTheKidsWantDjent 3154 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

have you tried going to settings -> Permalinks and choose Numeric and then change that back to whatever, you have it to before and then try again. I remember doing that for one of my projects and that fixed my problem.

本文标签: url rewritingHow to change URL for custom post type archive