Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.