Visual WYSIWYG editor should not be used . By default you get access to the “Visual” tab of the editor. This editor can modify all your XML/HTML tags that you have used and therefore you can lose any scripting logic. The editor will convert “<” or “>” to “<” or “>”.
If you are writing PHP code and calling it from the WordPress post or pages (this can be done by using appropriate WordPress plugins) then again you need to make sure that there are no new lines around the script tags. One technique I use is, I remove all new lines first and then echo the HTML code. Here is an example :