Custom upload directory per CPT; when removed, file not deleted

A small mistake, the return should be outside if

add_filter("upload_dir", function ($args) {
  $id = (isset($_REQUEST["post_id"]) ? $_REQUEST["post_id"] : "");

  if($id) {
    $newdir = "https://wordpress.stackexchange.com/" . get_post_type($id);
    ...
  }

  return $args;
});

Leave a Comment