Hi guys I'm working on this public theme where the previous developer had created a post type called "blog" the problem is that when you create a page with the same slug it creates a conflict.

The theme is being used by several clients and I'm trying to avoid this issue by renaming the post type without having the users/clients to run by any problem.

I'm doing the following:

$theme_executed = false;
if(!$theme_executed) {
 $theme_executed = true;

function theme_blog_news(){
  $theme_sql= mysql_query("UPDATE  wp_posts SET  post_type =  'news' WHERE  post_type = 'blog'");
  if (!$theme_sql) {
    die('Invalid query: ' . mysql_error());

It worked but I'm looking for a best practice or a more native way.


2 Answers 2


You are in the right direction. When doing something like this, make sure you look at every possible place where this needs to be changed as you don't want data inconsistency. Some suggestions to make this process better:

Don't hardcode WordPress table name ($wpdb->posts) in the query. This won't work if the install has a custom table prefix set in their wp-config.php

Save the version no of ur plugin and write upgrade functions which works on the basis of versions and then you can call them individually or in a batch checking how many upgrade functions needs to be run. Everytime you change something like this make a function that you will call if a client is upgrading from X version and then you can chain upgrade functions in a batch if the client hasn't updated from a long time.

  • Thanks, Yeah I figured out the $wpdb class later on, and that is how I use it, it's for a theme though so what I did was add an option to rename the post-type.
    – crissoca
    May 15, 2012 at 18:32

Admittedly, I've never tried this, but the Codex description of register_post_type() is:

Create or modify a post type.

Have you tried re-registering the post type with the new setting you want and then making sure it has a lower priority than the function that first registers the post type? It may just override the settings. (Sorry if you already tried this.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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