我想选择所有有特定文本字符串的wordpress帖子。
然后向所有这些帖子添加自定义字段。
这是我到目前为止得出的结论,但它不起作用
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\';
有人知道怎么做吗?
最合适的回答,由SO网友:Chelsea Urquhart 整理而成
给你(你真的很接近):
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 wp_posts.post_content LIKE \'%Customer Reviews%\'
AND wp_posts.post_type = \'post\';
`
编辑:您也可以将“正在”更改为“正在”。我重写了查询的from部分,因为子查询是不必要的。