WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question

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.

share|improve this answer
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 '12 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.)

share|improve this answer
Thanks man, I'll take a look at it. – crissoca May 15 '12 at 18:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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