最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom Post Type Archive Page URL

programmeradmin0浏览0评论

I created a custom post type called provider, and currently I have a URL structure like so:

  1. /provider/abc
  2. /provider/xyz
  3. etc...

Now I would like to add some content in the provider page, mostly for SEO reasons. After having a look at how archive pages are working, I found out that it would be best to just change the URL of the archive page for provider. So the new URL would be /provider-archive/ while keeping the same URL for the provider already in the system, so they would remain:

  1. /provider/abc
  2. /provider/xyz
  3. etc...

This way, I would be able to create a regular page and give it the /provider/ URL.

I am trying to do so by changing the rewrite, adding in a slug to be provider-archive. After doing all of this, and creating a new page with the URL /provider/, when I try to access said URL I still see the archive.

This is how my custom post type is set up:

/**
 * Register Provider Meta Box
 */

add_action('init', 'cpt_provider');
function cpt_provider()
{

    $labels = array(
        'name'               => _x('Providers', 'post type general name', 'mebo-cpt'),
        'singular_name'      => _x('Provider', 'post type singular name', 'mebo-cpt'),
        'menu_name'          => _x('Providers', 'admin menu', 'mebo-cpt'),
        'name_admin_bar'     => _x('Provider', 'add new on admin bar', 'mebo-cpt'),
        'add_new'            => _x('Add New', 'book', 'mebo-cpt'),
        'add_new_item'       => __('Add New Provider', 'mebo-cpt'),
        'new_item'           => __('New Provider', 'mebo-cpt'),
        'edit_item'          => __('Edit Provider', 'mebo-cpt'),
        'view_item'          => __('View Provider', 'mebo-cpt'),
        'all_items'          => __('All Providers', 'mebo-cpt'),
        'search_items'       => __('Search Providers', 'mebo-cpt'),
        'parent_item_colon'  => __('Parent Providers:', 'mebo-cpt'),
        'not_found'          => __('No Providers found.', 'mebo-cpt'),
        'not_found_in_trash' => __('No Providers found in Trash.', 'mebo-cpt')
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __('Description.', 'mebo-cpt'),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'capability_type'    => 'post',
        'rewrite'           => array( 'slug' => 'provider-archive' ),
        'hierarchical'       => true,
        'menu_position'      => null,
        'menu_icon'          => get_template_directory_uri() . '/img/icons/Gun-512.png',
        'supports'           => array('title', 'editor')
    );

    register_post_type('provider', $args);
}

Is there anything that I'm missing?

I created a custom post type called provider, and currently I have a URL structure like so:

  1. /provider/abc
  2. /provider/xyz
  3. etc...

Now I would like to add some content in the provider page, mostly for SEO reasons. After having a look at how archive pages are working, I found out that it would be best to just change the URL of the archive page for provider. So the new URL would be /provider-archive/ while keeping the same URL for the provider already in the system, so they would remain:

  1. /provider/abc
  2. /provider/xyz
  3. etc...

This way, I would be able to create a regular page and give it the /provider/ URL.

I am trying to do so by changing the rewrite, adding in a slug to be provider-archive. After doing all of this, and creating a new page with the URL /provider/, when I try to access said URL I still see the archive.

This is how my custom post type is set up:

/**
 * Register Provider Meta Box
 */

add_action('init', 'cpt_provider');
function cpt_provider()
{

    $labels = array(
        'name'               => _x('Providers', 'post type general name', 'mebo-cpt'),
        'singular_name'      => _x('Provider', 'post type singular name', 'mebo-cpt'),
        'menu_name'          => _x('Providers', 'admin menu', 'mebo-cpt'),
        'name_admin_bar'     => _x('Provider', 'add new on admin bar', 'mebo-cpt'),
        'add_new'            => _x('Add New', 'book', 'mebo-cpt'),
        'add_new_item'       => __('Add New Provider', 'mebo-cpt'),
        'new_item'           => __('New Provider', 'mebo-cpt'),
        'edit_item'          => __('Edit Provider', 'mebo-cpt'),
        'view_item'          => __('View Provider', 'mebo-cpt'),
        'all_items'          => __('All Providers', 'mebo-cpt'),
        'search_items'       => __('Search Providers', 'mebo-cpt'),
        'parent_item_colon'  => __('Parent Providers:', 'mebo-cpt'),
        'not_found'          => __('No Providers found.', 'mebo-cpt'),
        'not_found_in_trash' => __('No Providers found in Trash.', 'mebo-cpt')
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __('Description.', 'mebo-cpt'),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'capability_type'    => 'post',
        'rewrite'           => array( 'slug' => 'provider-archive' ),
        'hierarchical'       => true,
        'menu_position'      => null,
        'menu_icon'          => get_template_directory_uri() . '/img/icons/Gun-512.png',
        'supports'           => array('title', 'editor')
    );

    register_post_type('provider', $args);
}

Is there anything that I'm missing?

Share Improve this question asked Nov 7, 2020 at 18:53 mikkuslicemikkuslice 101
Add a comment  | 

1 Answer 1

Reset to default 0

I feel bad about this. But here's how I fixed it -> Save permalinks.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论