2D Roguelike - Not sure how to fix overlapping sprites

I’m making a 2d topdown game, and I’ve tried for a few days to fix this problem unsuccessfully. I’m using the Transparency Sort Axis to order sprites based on their Y value, so that for example a player could walk behind and then in front of a tree and it would render correctly in both situations. This part works perfectly, which is sort of where my problem comes from. If the player walks to the walls at the side, because they are high enough to go to a higher order in layer, their sprite will render on top and in between tiles.
alt text

I’m looking for any tips or advice on fixing this problem.

I think it might have to do with where your sprite pivots are.
Make sure both the wall and player pivots are at the bottom of the sprites.