pealo86 Posted September 10, 2011 Share Posted September 10, 2011 I have the following SELECT query for a Wordpress database: SELECT * FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id = 442); However I need to add an UPDATE statement in there too and have no idea how to go about it. Basically I have a field called 'post_type'. Any record that is returned in the results of the SELECT query needs to have its 'post_type' field value changed to 'featured-property'. Does anyone know how I would go about this? Quote Link to comment Share on other sites More sharing options...
pealo86 Posted September 10, 2011 Author Share Posted September 10, 2011 ...so something along the lines of: UPDATE wp_posts SET post_type='featured-property' WHERE some_column=post Quote Link to comment Share on other sites More sharing options...
pealo86 Posted September 10, 2011 Author Share Posted September 10, 2011 Okay bit of an update, I'm now using the following code: UPDATE wp_posts SET post_type='featured-property' WHERE post_type IN ( SELECT ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id = 442 ) However it is throwing the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11 I don't understand as there is no " character on line 11? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 10, 2011 Share Posted September 10, 2011 does post_type = wp_posts.ID ? Quote Link to comment Share on other sites More sharing options...
pealo86 Posted September 10, 2011 Author Share Posted September 10, 2011 Hmmm I'm not sure? But I've just tried: UPDATE wp_posts SET post_type='featured-property' WHERE wp_posts.ID IN ( SELECT ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id = 442 ) and got the same error about line 11 Quote Link to comment Share on other sites More sharing options...
fenway Posted September 10, 2011 Share Posted September 10, 2011 You're missing a close paren for the ON close. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.