0

I trying to update menu_order if post_type product not have _thumbnail... Tried:

UPDATE phiz_posts SET menu_order = 1 WHERE ID IN (SELECT ID FROM phiz_posts LEFT JOIN phiz_postmeta ON phiz_posts.ID = phiz_postmeta.post_id AND phiz_postmeta.meta_key = '_thumbnail_id' WHERE post_type='product' AND phiz_postmeta.post_id IS NULL)

Error: You can't specify target table 'phiz_posts' for update in FROM clause

This sql return the list of product ID without _thumbnail correctly:

SELECT ID FROM phiz_posts LEFT JOIN phiz_postmeta ON phiz_posts.ID = phiz_postmeta.post_id AND phiz_postmeta.meta_key = '_thumbnail_id' WHERE post_type='product' AND phiz_postmeta.post_id IS NULL

How can change this ?

Best,

0
UPDATE phiz_posts p SET menu_order = 1 WHERE ID NOT IN (SELECT post_id FROM phiz_postmeta WHERE meta_key = '_thumbnail_id') 
AND post_type = 'product' 
AND post_status = 'publish'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.