I want to select all wordpress posts that have a certain text string.
Then to add a custom field to all those posts.
Here is what I figured out so far but it doesn't work
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id,
'customer_reviews' AS meta_key,
'On_or_delete' AS meta_value
FROM wp_posts
WHERE ID IS IN
(SELECT post_id
FROM wp_posts
WHERE post_content LIKE '%Customer Reviews%')
AND post_type = 'post';
Anyone know how to do this please?
select all posts where post_content like 'something'and do a PHP loop to add the custom fields. If this is the only issue, the Question is off-topic (pure PHP and/or pure MySQL).update_post_meta(). If your Question is simply how to correct this SQL query, I believe it's off-topic here, it's being close-voted as such, and candidate to migration to Stack Overflow.