I want to bulk add a custom field (category) with value (photography) to all posts in a specific category (photography, with Category ID 5).
I have used the code below to bulk add a custom field to all posts, but how can I narrow this down to a specific category? Anyone?
This is the code I used for all posts:
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT wp_posts.ID, 'category', 'photography'
FROM wp_posts
WHERE wp_posts.post_status = 'publish'
You can use WordPress functions to do this and just run it once, a fast example would be.
Remember to remove the function after it runs because you don’t want it to run on every load.