-
-
Save tommcfarlin/a4b657f93a5df41274f5b4744975d265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function setInactivePosts() | |
{ | |
// First, find the post IDs with an empty acme-status. | |
global $wpdb; | |
$results = $wpdb->get_results( | |
$wpdb->prepare( | |
" | |
SELECT post_id | |
FROM $wpdb->postmeta | |
WHERE meta_key = %s | |
AND meta_value = '' | |
", | |
'acme-status' | |
) | |
); | |
// More to come... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// See previous gist. | |
// If there aren't any results, there's nothing to do. | |
if (0 === \count($results)) { | |
return; | |
} | |
// More to come... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// See previous gist. | |
// Otherwise, set the post_status of the specified post IDs to 'draft'. | |
foreach ($results as $result) { | |
$wpdb->get_results( | |
$wpdb->prepare( | |
" | |
UPDATE $wpdb->posts | |
SET post_status = %s | |
WHERE ID = %d | |
", | |
'draft', | |
(int) ($result->post_id) | |
) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function setInactivePosts() | |
{ | |
// First, find the post IDs with an empty acme-status. | |
global $wpdb; | |
$results = $wpdb->get_results( | |
$wpdb->prepare( | |
" | |
SELECT post_id | |
FROM $wpdb->postmeta | |
WHERE meta_key = %s | |
AND meta_value = '' | |
", | |
'acme-status' | |
) | |
); | |
// If there aren't any results, there's nothing to do. | |
if (0 === \count($results)) { | |
return; | |
} | |
// Otherwise, set the post_status of the specified post IDs to 'draft'. | |
foreach ($results as $result) { | |
$wpdb->get_results( | |
$wpdb->prepare( | |
" | |
UPDATE $wpdb->posts | |
SET post_status = %s | |
WHERE ID = %d | |
", | |
'draft', | |
(int) ($result->post_id) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment