title: MySQL trigger and conditional update
body: <p>I want to create a MySQL trigger on <code>INSERT</code>: when a new record is inserted in the <code>wp_posts</code> table, I want to update <code>wp_posts.post_author</code> retrieving the data from other two tables, using two subqueries (I suppose this can be done better). </p>
  
  <p>Anyway, the update should be "conditional", that is the row must be updated only if <code>wp_posts.post_title</code> value is "A", "B" or "C". Is this possible? </p>
  
  <p>This is what I tried: </p>
  
  <pre><code>CREATE TRIGGER updatePostIDonInsert
  AFTER INSERT
     ON wp_posts FOR EACH ROW
  
  BEGIN
  
     -- variable declarations
  
     -- trigger code
  // ? (pseudo: if wp_posts.post_title IN ("A","B","C") then...)
  
  UPDATE wp_posts SET post_author = 
  (SELECT ID from wp_users WHERE user_email = 
  (SELECT meta_value FROM `wp_postmeta` WHERE post_id = wp_posts.ID AND meta_key = "_from_email"))
  
  END;
  </code></pre>
  
  <p>Any help is appreciated</p>
  
  <p>[UPDATE] the latest query I tried:</p>
  
  <pre><code>CREATE TRIGGER updatePostIDonInsert
      BEFORE INSERT
         ON wp_posts FOR EACH ROW
      BEGIN
  
      IF FIND_IN_SET(NEW.post_title,'General contact,Website contact,Master contact') &gt; 0 AND NEW.post_type ='inbound_com' THEN
      SET NEW.post_author = (SELECT ID from wp_users WHERE user_email = (SELECT meta_value FROM wp_postmeta WHERE post_id = NEW.ID AND meta_key = '_from_email'));
  
      END IF;
  
      END;
  </code></pre>
  
  <p>(this works if inserted via PhpMyAdmin trigger section, but without the final END and starting from IF)</p>