douba5540 2014-06-24 09:34
浏览 57
已采纳

在wordpress中重命名我的自定义帖子类型的slug不再起作用并且保留旧的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". 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. 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.

  • 写回答

1条回答 默认 最新

  • duanfu6160 2014-08-25 15:03
    关注

    I solved the problem myself by going to Settings->permalinks in the wordpress cms and changing the setting to a different one. Save it after doing this and refres your page.

    Changing it back after this solved my problem!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器