Sql Update CPT from publish to draft and particular custom field

admin2025-06-05  1

I have:

CPT: match custom field: played

Is it possible by MySql to change the status from publish to draft of all posts of CPT 'match' with custom field set as '0'?

A good start can be

UPDATE wp_posts SET post_status = 'draft' WHERE post_type = 'match' AND meta_key = 'played' AND meta_value = 0;

but meta_key and meta_value are not in wp_posts table.

Thanks a lot for your support

I have:

CPT: match custom field: played

Is it possible by MySql to change the status from publish to draft of all posts of CPT 'match' with custom field set as '0'?

A good start can be

UPDATE wp_posts SET post_status = 'draft' WHERE post_type = 'match' AND meta_key = 'played' AND meta_value = 0;

but meta_key and meta_value are not in wp_posts table.

Thanks a lot for your support

Share Improve this question edited Dec 5, 2018 at 19:06 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 17:47 GiulioGiulio 511 silver badge8 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

You'll have to use JOIN to achieve this:

UPDATE wp_posts p INNER JOIN wp_postmeta pm ON p.ID = pm.post_id 
SET p.post_status = 'draft'
WHERE p.post_type = 'match' AND pm.meta_key = 'played' AND pm.meta_value = 0;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749125772a316582.html

最新回复(0)