[英]Renaming the slug of my custom post type in wordpress doesnt work anymore and keeps the old slug
I have been working on a Wordpress theme for a few weeks now and i am facing the following problem: I have a custom post type called "Guide" and I used the rewrite slug to change this to "stappenplan". 我一直在研究Wordpress主题已有几个星期,并且面临以下问题:我有一个名为“ Guide”的自定义帖子类型,并且我使用了重写方法将其更改为“ stappenplan”。 Now I would like to change this to "application" but the rewrite doesnt work.
现在,我想将其更改为“应用程序”,但重写无效。 it doesnt even reach the Archive.php file which is weird.
它甚至没有到达奇怪的Archive.php文件。 I am using the following code to register my custom post type.
我正在使用以下代码注册我的自定义帖子类型。
$guides = new \KC\ContentType('Guide',
['rewrite' => ['slug' => 'application'],'menu_icon' => get_template_directory_uri().'/img/icons/application.svg','has_archive' => true],
['plural_name' => 'Applications']);
and a helper class which looks as follows: 和一个帮助器类,如下所示:
<?php
namespace KC;
class ContentType {
public $type;
public $options = [];
public $labels = [];
/**
* Creates a new ContentType object
* @param string $type
* @param array $options
* @param array $labels
*/
public function __construct($type, $options = [], $labels = []) {
$this->type = $type;
$default_options = [
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => ['slug' => strtolower($type)],
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => true,
'taxonomies' => ['post_tag','category'],
'supports' => ['title', 'editor', 'revisions', 'thumbnail','page-attributes','excerpt']
];
$required_labels = [
'singular_name' => ucwords($this->type),
'plural_name' => ucwords($this->type)
];
$this->options = $options + $default_options;
$this->labels = $labels + $required_labels;
$this->options['labels'] = $labels + $this->default_labels();
add_action('init', array($this, 'register'));
}
/**
* Registers the content type using WP core function(s)
* @return null
*/
public function register() {
register_post_type($this->type, $this->options);
}
/**
* Creates intelligent default labels from the required singular and plural labels
* @return array
*/
public function default_labels() {
return [
'name' => $this->labels['plural_name'],
'singular_name' => $this->labels['singular_name'],
'add_new' => 'Add New ' . $this->labels['singular_name'],
'add_new_item' => 'Add New ' . $this->labels['singular_name'],
'edit' => 'Edit',
'edit_item' => 'Edit ' . $this->labels['singular_name'],
'new_item' => 'New ' . $this->labels['singular_name'],
'view' => 'View ' . $this->labels['singular_name'] . ' Page',
'view_item' => 'View ' . $this->labels['singular_name'],
'search_items' => 'Search ' . $this->labels['plural_name'],
'not_found' => 'No matching ' . strtolower($this->labels['plural_name']) . ' found',
'not_found_in_trash' => 'No ' . strtolower($this->labels['plural_name']) . ' found in Trash',
'parent_item_colon' => 'Parent ' . $this->labels['singular_name']
];
}
}
Hopefuly this is just my bad and not a Wordpress issue. 希望这只是我的问题,而不是Wordpress问题。
I solved the problem myself by going to Settings->permalinks in the wordpress cms and changing the setting to a different one. 我自己解决了该问题,方法是转到wordpress cms中的“设置”->“永久链接”,然后将设置更改为其他设置。 Save it after doing this and refres your page.
执行此操作后保存并刷新您的页面。
Changing it back after this solved my problem! 解决了我的问题后将其更改回!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.