SQL insert a foreach select on same table?
Can I, instead of doing this via PHP, combine this in 1 sql statement?
object_ids = "select object_id from `wp_term_relationships` where `term_taxonomy_id` = 14;";
foreach(object_ids as object_id)
{
"insert into `wp_term_relationships` VALUES (" . object_id . ",1597,0);";
}
(for WordPress: for every post 开发者_如何学编程that has a category (14) add a new term relationship (1597))
INSERT INTO `wp_term_relationships`
SELECT object_id, 1597, 0
FROM `wp_term_relationships`
WHERE `term_taxonomy_id` = 14;
Better something like:
INSERT INTO wp_term_relationships
SELECT object_id, 1597, 0
FROM wp_term_relationships
WHERE term_taxonomy_id = 14
精彩评论