Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active May 7, 2019 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/a4b657f93a5df41274f5b4744975d265 to your computer and use it in GitHub Desktop.
Save tommcfarlin/a4b657f93a5df41274f5b4744975d265 to your computer and use it in GitHub Desktop.
<?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...
<?php
// See previous gist.
// If there aren't any results, there's nothing to do.
if (0 === \count($results)) {
return;
}
// More to come...
<?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)
)
);
}
<?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