One thing to note. If you are using a search plugin like Relevanssi you will need to turn it off for this code to work. You may be able to mess with the priority of the call to get it to work but I didn't look into that.