0

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?

2

1 Answer 1

0

Sorted this out. In my case, I had Category base also set to news-insights, so Wordpress was trying to find a category with the slug of the post. Removing the category base solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.