How to Set Post Status to Draft if older than today

Your query isn’t giving you a post ID, it’s giving you an entire post. The SELECT * returns all columns, ID, post_status, etc. So setting $my_post['ID'] = $a doesn’t do anything for you in this case.

Try using: $my_post['id'] = $a->ID; instead. That should accurately set your ID before you call wp_update_post() and you should be in business.

Aside from that, I see no problems with what you’re doing … except that querying the database every time the site is loaded might eventually create performance issues. I’d set up an hourly chron job instead to automate the process … then it doesn’t depend on or slow down user traffic.