3
votes

I have millions of posts (using a custom post type called "case"). They each have a lot of post_meta records (using ACF). I now want woocommerce to treat these "case" CPTs as products (without changing their actual post type to "product"). I'm using Reigel Gallarde's plugin which sets up woocommerce to treat any CPTs as products. It kind of works. But the problem is that I am forced to go into each "case" post edit screen and re-save the post in order for woocommerce to finally recognize it as a product. Obviously, it is impractical to manually do this for millions of posts. So how can I otherwise trick woocommerce into recognizing these? Can I add a minimum of post meta fields or do something else in the database or in functions code in order for them to be recognized?

NOTE: A correct answer should NOT require changing the post_type of these items to "product".

1

1 Answers

1
votes

run a query in your data base:

  1. make a copy of your DB.
  2. run the query: UPDATE wp_posts SET post_type = 'product' WHERE post_type = 'post'; but using $wpdb.

If you don't know anything of code you can use a hook to run that query when you update one post, then you delete the code.

function runQuery(){
    global $wpdb;
    $wpdb->update(
        $wpdb->posts,
        array('post_type' => 'product'),
        array('post_type' => 'post'),
        array('%s'),
        array(''%s0)
    );

}

add_action( 'save_post', 'runQuery' );

Add this to functions.php