Section 13. The rights of an attaching creditor shall not prevail as against a lien under section 1, nor against the claim of a lienor if notice or notices of contract have been filed or recorded in the registry of deeds under sections 2, 2C, 2D or 4 prior to the recording of the attachment. An attachment recorded prior to the filing or recording of the notice of contract shall prevail against a lien, other than for personal labor, to the extent of the value of the buildings and land as they were at the time when the labor was commenced or the material furnished or professional services were commenced for which the lien is claimed and, in case of a sale under section 18, the court shall determine what proportion of the proceeds of the sale, as derived from the value of the property at such time, shall be held subject to the attachment. If the attaching creditor recovers judgment, the proceeds so held subject to his attachment, or as much thereof as may be necessary, shall be applied upon his execution, and the residue, if any, shall be disposed of in the same manner as if there had been no such attachment. If the interest of the owner of the property is attached after the filing of the notice, the proceeds of any sale of the property under said section eighteen, after discharging all prior liens and claims, shall be applied to satisfy the execution of the attaching creditor, provided the lienor or the officer making the sale has actual notice of the attachment. Several attaching creditors as between themselves shall be paid according to the order of their attachments. Liens of a trustee or trustees of a fund or funds, described in section one, providing coverage or benefits for persons shall be considered as liens for personal labor.