Optimize posts check method

Put the loop inside the condition, instead of always running the loop and always checking the condition