SQl query to add post meta to all posts

Example: The following code will add the custom field (meta key), “featured” for all posts and set the value to 0

//Do this in phpmyadmin
INSERT INTO wp_postmeta( post_id, meta_key, meta_value )
SELECT DISTINCT ID AS post_id, ‘featured’ AS meta_key, 0 AS meta_value
FROM wp_posts
WHERE post_type = ‘post’ AND post_status = ‘publish’

Leave a Reply