我有以下查询:
SELECT ID
FROM `wp_posts` as ps
INNER JOIN `wp_term_relationships` as tr
ON ps.ID = tr.object_id
WHERE ps.post_date < '2011-06-07' /*Get posts before June 6th 2011*/
AND ps.post_title
LIKE '%MY SEARCH STRING %' /*A String im looking for in post titles*/
AND tr.term_taxonomy_id = '548'/*My Category ID*/;
我需要查询为每个结果ID插入特定数据。理论上:
INSERT IGNORE INTO wp_postmeta (post_id,meta_key, meta_value)
VALUES (IDs from selection above,_thumbnail_id,11059)
这会在上面特定选项的所有帖子中将meta_key
设置为_thumbnail_id
和meta_value
为11059
。
使用wp_postmeta
而不是meta_id
wp_postmeta (post_id ..)
自动增量列的wp_postmeta (meta_id,post_id ..)
自动增量列
答案 0 :(得分:0)
INSERT IGNORE INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_thumbnail_id', 11059
FROM `wp_posts` as ps
INNER JOIN `wp_term_relationships` as tr ON ps.ID = tr.object_id
WHERE ps.post_date < '2011-06-07'
AND ps.post_title LIKE '%MY SEARCH STRING %'
AND tr.term_taxonomy_id = '548'
答案 1 :(得分:0)
INSERT IGNORE INTO wp_postmeta
SELECT ID, NULL, 11059
FROM `wp_posts` as ps
INNER JOIN `wp_term_relationships` as tr ON ps.ID = tr.object_id
WHERE ps.post_date < '2011-06-07'
AND ps.post_title LIKE '%MY SEARCH STRING %'
AND tr.term_taxonomy_id = '548';