SQL query to add post meta for each WordPress post

To add post meta to all posts (posts with post type “post”) in your WordPress database you should use the following SQL query:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, 'meta-key', 'meta-value' FROM wp_posts WHERE post_type = 'post';

To add post meta to another post type, simply change the post type in the WHERE clause.

Robbert Vermeulen

Need help from a WordPress expert?

I would love to hear about your project and how I can help you achieve your goals