This research aims to optimize the fluid flow and heat transfer features of a porous square cavity filled with $ {\rm TiO}_2-{\rm H}_2{\rm O} $ TiO2-H2O (titanium oxide-water) nanoliquid under the influence of magnetic field and the heat source or sink.The non-dimensional version of partial differential equations is solved using the marker-and-cell technique (MAC) and the finite difference methodol.The left and right walls are adiabatic.The top wall is cooled, and the bottom wall is heated completely.Spherical $ ({\rm TiO}_2) $ (TiO2) and non-spherical shapes (hexahedron, tetrahedron, column and lamina) nanoparticles are utilized to examine the optimal heat transference and fluid circulations within the enclosure.The impacts are graphically visualised and discussed with the following parameters nanoparticles volume fraction $ \left (\varphi \right ) $ (φ), heat source or sink (Q), Darcy number (Da), Rayleigh number (Ra), and Hartmann number (Ha).Of the four non-spherical configurations of nanoparticles, lamina nanoparticles provide the best thermal transference and fluid velocity inside the cavity.The average heat transfer rate improved by $ 45.81\% $ 45.81% when $ 5\% $ 5% nanoparticles were added to the base fluid.The maximum heat transmission rate is provided by nanoparticles that are lamina-shaped.