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.

Leave a reply

Feel free to ask questions or make comments.


    No comments yet..