Can a parent have the court order the child to remain in parents custody until 18yr of age?

If you are divorced and granted custody that court order is valid unless the other parent (or the state) get custody for whatever reason (if both parents become unfit etc). And custody lasts until the child is 18. You can not get a guarantee from the judge that you as a parent will have custody until the child is 18. There are 2 parents and according to the law both are allowed to seek custody of their child.