Use Repository Pattern in WP theme

In my template files I have a lot of WP_Query to get posts of an author or from a specif category ecc... I'm thinking to use Repository Patter in order to have cleaner code and a layer between database and theme.

This PostRepository class will have some methods like: - getByID - getByAuthor - getByCategory

Could be a good idea? Have somebody use somethink like this?

Topic oop wp-query repository Wordpress

Category Web


Yes absolutely, It would be great to abstract away your queries at a single place. You might also use caching in your repository.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.