This should work for you and you do not need to use this each time you add a post. Using
WP_Query is the better approach. Another way will be using raw queries. If you need that, then we will need some time to prepare that. Please confirm whether the existing approach works for you or not. Thanks..