0

I am trying to convert over 2000 posts with a category of hp_operator, to a custom post type.

I usually use the "Convert Post Types" (a plugin) for tasks like this but with the amount of posts here it can't handle this in one task.

Maybe it is better to do it within the database with a SQL query? It should do some like following:

  • Select all post with the category term hp_op
  • Change/convert their post type to hp_op (a custom post type)
2

Look at this Bulk post type conversion, there are listed SQL/WP ways to do that. Try to do that yourself first with a db copy.

In phpMyAdmin there is a box to run queries, called "SQL". You can see a demo here http://demo.phpmyadmin.net/master-config/

| improve this answer | |
  • I use navicat for my queries, will take a look at that link, many thanks – James Feb 18 '16 at 11:14
1

I got really rusted with MySQL, but here is snipped that worked. It could have some mistakes as I said I got really rusted (e.g. make a backup first):

UPDATE  `wp_posts` p 
    LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID
    LEFT OUTER JOIN wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id
    LEFT OUTER JOIN wp_terms t ON t.term_id = x.term_id
    SET  p.post_type =  'new_post_type'
    WHERE p.post_status = 'publish'
    AND p.post_type = 'post'
    AND t.slug = 'customcat';

Here new_post_type should be hp_op and customcat should be hp_op. Although I think it would be more appropriate to use the build in functions in WP. Tested in on 10 posts and it worked - all posts with specific category were transferred as custom posts.

p.s. the category should be your category slug. I saw there is some digit after it's name.

| improve this answer | |

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.