Please note that the majority of the hacks reported are most likely due to outdated applications. Most of the times hackers leave backdoors in the document root of your website to regain access. It is also possible that some plugins have poor scripts, which allows hackers to insert various malformed queries and remotely execute the code and perform any intended action.
You can follow the below steps to harden your website security and prevent it from happening again.
Scan the files and database. Wordfence plugin can be handy here.
Make sure Dangerous PHP functions are disabled. Some common functions to rule out are eval, preg_replace, exec etc.
Disable PHP execution in the uploads folder.
Restrict wp-admin to certain IPs from which you access Wp-admin Dashboard.
Remove unused themes and plugins.
Limit Access to the Wp-Content Directory.
Restrict access to PHP files from plugin and theme directories.
Most of the hardening rules will be configured via .htaccess and make sure that your WordPress core, plugins and themes are all up to date.
Let me know if you have any further questions.