【发布时间】: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.stackexchange.com/questions/53298/…,我认为 get_option('gallery_slug') 没有抛出任何值,因为它重定向到 404
-
大多数情况下,永久链接刷新是这类问题的答案。
标签: wordpress hook custom-post-type options