I have the following code to change Posts to News, and add news-insights
to the URL of every post:
function cp_change_post_object() {
$get_post_type = get_post_type_object('post');
$labels = $get_post_type->labels;
$labels->name = 'News & Insights';
$labels->singular_name = 'News';
$labels->add_new = 'Add News';
$labels->add_new_item = 'Add News';
$labels->edit_item = 'Edit News';
$labels->new_item = 'News';
$labels->view_item = 'View News';
$labels->search_items = 'Search News';
$labels->not_found = 'No News found';
$labels->not_found_in_trash = 'No News found in Trash';
$labels->all_items = 'All News';
$labels->menu_name = 'News & Insights';
$labels->name_admin_bar = 'News & Insights';
}
add_action( 'init', 'cp_change_post_object' );
function modify_post_type_post() {
$post_type = 'post';
$post_type_object = get_post_type_object($post_type);
$post_type_object->has_archive = true;
$post_type_object->rewrite = array('slug' => 'news-insights', 'with_front' => false);
register_post_type($post_type, $post_type_object);
};
add_action('init', 'modify_post_type_post');
Everything is working correctly, including the has_archive
declaration, but the URLs are not being rewritten. They're still top-level (domain.com/news-slug). My permalink setting is on Post name. Flushing permalinks has no effect, and all other custom post type URL rewrites are working as expected. What's going on?
register_post_type_args
filter to change the post type declaration, alsopost
post type. "Is there possible way to modify custom post type?"