WordPress MySQL: add new term relationships if term_taxonomy_id == 4

I need to find rows with term_taxonomy_id == 4 and add new term relationships, kind of like that:
http://picpaste.com/28dbd65ee0-hRbWftsI.jpg

On the screenshot the post with object_id == 2108 has term relationships 57, 60, 62 and 64 — and I need an every post linked with term_taxonomy_id == 4 has the same relationships too… I haven’t worked with SQL much, so I got stuck with that. Which SQL commands should I use (except INSERT INTO wp_term_relationships, I got it).

Read More

http://picpaste.com/28dbd65ee0-hRbWftsI.jpg

Related posts

1 comment

  1. Did it myself:

    CREATE TEMPORARY TABLE temp_table AS SELECT *
    FROM wp_term_relationships
    WHERE term_taxonomy_id = '4';
    UPDATE temp_table SET term_taxonomy_id = '58' WHERE term_taxonomy_id = '4';
    INSERT INTO wp_term_relationships
    SELECT *
    FROM temp_table;
    DROP TEMPORARY TABLE temp_table;
    

Comments are closed.