I have made a plugin that uses a CPT and a few metadatas. The plugin comes in two versions A and B.
Version A has one post meta less then version B called 'score'. When users update the plugin from A to B I need the score meta to be created for all custom posts for version B to work properly.
This is the insert query I have used:
global $wpdb; $wpdb->query( " INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) SELECT p.ID, 'score' AS meta_key, 0 AS meta_value FROM $wpdb->posts AS p WHERE p.post_type = 'my_cpt' " );
This query works to add the new metadata but will create duplicates if runned multiple times. What should I do to make the query add the metadata only if it does not exist already?
Thanks for any possible solution.