I’m running the YouTube Video Fetcher plugin at . It fetches videos using the youtube api and displays them on your website.
Within the plugin script, there is the following sequence:
if (empty($items)) {$ret .= " 'No new videos.'";}
else foreach ( $items as $item ) :
Is it possible to change the wordpress post status from published to draft if “No new videos” are found?
I am thinking the solution is using the wp update post function and something along the lines of the following:
<?php
// Update post
$my_post = array();
$my_post['ID'] = $id;
$my_post['post_status'] = 'draft';
// Update the post into the database
wp_update_post( $my_post );
?>
1
I guess it should work . As long as $id
is available things are easy.
<?php
if (empty($items)) {
$ret .= " 'No new videos.'";
$postid = $post->ID; //Supply post-Id here $post->ID.
wp_update_post(array(
'ID' => $postid,
'post_status' => 'draft'
));
}
else
foreach ( $items as $item ) :
?>
Give it a shot.