Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been given a client's wordpress site to update & improve. Biggest problem - I need to take about 200+ posts of a specific category, 'reviews' and convert them all into a custom post type 'reviews'.

On top of this I need to move a few custom fields that have been attributed to these posts, so they remain intact once moved.

I expect I'll have to write a custom script that will change the mysql direct. But before I get my hands dirty- does anyone have any experience with doing this? Any tips/ gotchas/ scripts out there I can use?

Cheers

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You are not really moving anything just changing a simple field named post_type for each post so you don't have to worry about custom fields or anything else.

Simply get the post id's for the posts you need to change and change them and if you don't want to create a custom sql query for that you can even do that by WordPress:

//first get the post_ids as an array
/*the SQL way 
    global $wpdb;
    $querystr = "
        SELECT * FROM $wpdb->posts
        LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
        LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
        WHERE $wpdb->terms.name = 'CAGETORY_NAME'
        AND $wpdb->term_taxonomy.taxonomy = 'category'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
    ";

    $post_ids = $wpdb->get_results($querystr); 
*/
//
//
//
/* the WordPress Way */
        $post_ids = get_posts(array('post_per_page' => -1, 'cat' => category_id));
    //then update each post
        foreach($post_ids as $p){
            $po = array();
            $po = get_post($p->ID,'ARRAY_A');
            $po['post_type'] = "NEW_TYPE_NAME";
            wp_update_post($po);
        }
share|improve this answer
    
Brilliant. After posting this I started mucking about with the database and found it was a lot simpler than I thought it may be. Thanks Bainternet! –  Michael Watson Aug 17 '11 at 12:39

You can just use this plugin:

http://wordpress.org/extend/plugins/convert-post-types/

share|improve this answer

You can do this directly through SQL as well (important if you have an enormous content library). In doing so, you probably want to update the guid as well. SQL for updating both post_type and guid:

UPDATE wp_posts p
LEFT JOIN wp_postmeta pm ON p.ID=pm.post_id
SET
    p.post_type='NEW_POST_TYPE',
    p.guid=REPLACE(p.guid, 'OLD_POST_TYPE', 'NEW_POST_TYPE')
WHERE
    p.post_type='OLD_POST_TYPE'
share|improve this answer

Your Answer

 
discard

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.