Fixed the bugs in /api/posts sql queries