In this study, a new cavity form filled under a constant magnetic field by Ag/MgO/H2O nanofluids and porous media consistent with natural convection and total entropy is examined. The nanofluid flow is considered to be laminar and incompressible, while the advection inertia effect in the porous layer is taken into account by adopting the Darcy–Forchheimer model. The problem is explained in the dimensionless form of the governing equations and solved by the finite element method. The results of the values of Darcy (Da), Hartmann (Ha) and Rayleigh (Ra) numbers, porosity (εp), and the properties of solid volume fraction (ϕ) and flow fields were studied. The findings show that with each improvement in the Ha number, the heat transfer rate becomes more limited, and thus the magnetic field can be used as an outstanding heat transfer controller.