【问题标题】:Clear rewrite rule wordpress清除重写规则wordpress
【发布时间】:2018-07-31 11:08:40
【问题描述】:

我已经创建了一个选项页面,用于为我的自定义帖子类型创建动态 slug,并且工作正常。但是当我使用选项中的值更改自定义帖子类型中的 slug 时,页面显示 404。

$labels = array(
    'name' => _x('Gallery', 'post type general name'),
    'singular_name' => _x('Gallery', 'post type singular name'),
    'add_new' => _x('Add New', 'Gallery'),
    'add_new_item' => __('Add New Gallery'),
    'edit_item' => __('Edit Gallery'),
    'new_item' => __('New Gallery'),
    'view_item' => __('View Gallery'),
    'search_items' => __('Search Galleries'),
    'not_found' => __('No Galleries found'),
    'not_found_in_trash' => __('No Galleries found in Trash'),
    'parent_item_colon' => ''
);
$args = array(
        'labels' => $labels,
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' =>get_option('gallery_slug')),
        'taxonomies'  => array('category'),
        'supports' => array('title','thumbnail')
    );
register_post_type('gallery', $args);

我已经添加了下面的代码来清除重写规则,但是它不起作用,并且仍然显示404页面

add_action('update_option_gallery_slug','flush_rewrite_rules', 10, 2);

【问题讨论】:

标签: wordpress hook custom-post-type options


【解决方案1】:

尝试刷新永久链接 - 转到“设置 > 永久链接”并点击“保存更改”。每次更改帖子类型名称或 slug 时都需要这样做。

【讨论】:

    猜你喜欢
    • 2012-11-21
    • 2023-03-27
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    相关资源
    最近更新 更多