I have thousands of offline links in my posts, and I'd like to set them all to draft. I know the links are in the format example.com/fileX. So I needed a SQL query to search the post content and whatever post that contain that url will be set to draft.

I think this might be a good start:

UPDATE tb_posts 
SET post_status = 'draft' 

But I don't know to do the search inside the WHERE clause. I intend to use ARI Adminer Plugin to edit the database.

1 Answer 1


You could try to loop through all the posts and if the content contains the link, call this: change_post_status(get_the_ID(),'private'); or try draft if appropriate.

Register this function first:

function change_post_status($post_id,$status){
    $current_post = get_post( $post_id, 'ARRAY_A' );
    $current_post['post_status'] = $status;
  • Should I add this to the functions.php? Jul 1, 2018 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.