Does bankruptcy work the same way for a mortgage or car loan as it does for credit card debt?
No. Secured debts are treated differently than unsecured debts in bankruptcy.
Credit card debts, personal loans, medical bills, utility bills, among others, are unsecured, meaning that the creditor does not have a lien on anything you own. When the creditor has been given a lien on your house, your car, or jewelry or furniture that you bought with a payment plan, your house, your car, etc. is considered collateral for the loan, and the debt is a "secured debt." Whether you file a Chapter 7 bankruptcy or a Chapter 13 bankruptcy, secured debts are still treated differently.
In chapter 7, the goal is to discharge your debts without a repayment plan
With very few exceptions, all of your debts will be discharged (some exceptions are domestic support obligations, income taxes, student loans, those being non-dischargeable). Your obligation to pay secured and unsecured debts is ended by the Chapter 7 discharge. However, since secured creditors also have collateral which can be foreclosed on or repossessed despite the discharge of your personal liability to repay them, you would have to voluntarily continue paying the secured creditors in order to avoid losing the collateral after a Chapter 7 discharge.
Some people owe more on a car than the car is worth, or have a mortgage on a house that is in bad condition and isn’t worth the amount owing on the mortgage. They can choose to give the car back to the lender, or give the house back to the bank, rather than continuing to pay the secured debt. If they did that without filing a bankruptcy, the creditor might get far less from selling the collateral than the amount which was owed, and the creditor would then demand that the remaining balance of the debt be paid. A bankruptcy discharge prevents the lender from suing them for any deficiency still owing after the lender has sold the collateral.
In a case in which there are valuable assets which are worth more than the debtor can protect from the trustee by claiming the assets as exempt, the Chapter 7 trustee uses the money obtained from selling non-exempt assets to pay unsecured creditors. More often than not, the Chapter 7 trustee simply abandons assets that are collateral for secured debts, forcing the secured creditors to try to get their money by selling the collateral after repossession or foreclosure. Sometimes, a non-exempt asset which has a lien on it, such as real estate worth more than a mortgage on the property, will be sold by a Chapter 7 trustee, with the secured creditor being paid from the sale proceeds first, and the remaining proceeds becoming available for payment of unsecured creditors.
In a chapter 13 case, the law protects secured creditors against not being paid under a plan
That is, if the debtor chooses to keep the house or car, secured creditors must be paid.
For example, if the loan is secured by a car, the plan must provide for the car loan to be paid as a condition to the debtor keeping the car. This is true whether the debtor has enough income to really be able to afford the car or not.
As for unsecured debts, the debtor’s ability to afford to repay them affects whether or not the plan must provide for them to be paid. Depending on your income, you might not have to pay anything at all to unsecured creditors under a plan, and unsecured creditors do not get a choice. Unsecured creditors can object to a plan that does not pay provide for them to be repaid, but only if they can show that the debtor is not proposing to pay as much as the debtor can afford.