We consider a gravitational model in which matter is non-minimally coupled to geometry, with the effective Lagrangian of the gravitational field being given by an arbitrary function of the Ricci scalar, the trace of the matter energy-momentum tensor, and the contraction of the Ricci tensor with the matter energy-momentum tensor. The field equations of the model are obtained in the metric formalism, and the equation of motion of a massive test particle is derived. In this type of models the matter energy-momentum tensor is generally not conserved, and this non-conservation determines the appearance of an extra-force acting on the particles in motion in the gravitational field. The Newtonian limit of the model is also considered, and an explicit expression for the extra-acceleration which depends on the matter density is obtained in the small velocity limit for dust particles. We also analyze in detail the so-called Dolgov-Kawasaki instability, and obtain the stability conditions of the model with respect to local perturbations. A particular class of gravitational field equations can be obtained by imposing the conservation of the energy-momentum tensor. We derive the corresponding field equations for the conservative case by using a Lagrange multiplier method, from a gravitational action that explicitly contains an independent parameter multiplying the divergence of the energy-momentum tensor. The cosmological implications of the model are investigated for both the conservative and non-conservative cases, and several classes of analytical solutions are obtained.