Skip to content
Advertisement

Search by post title wordpress without reflesh

I want to create wordpress search by title without refleshing page. New results have to be shown when more than 3 symbols are typed in search. I’ve got input with form:

JavaScript

But when I’m typing – value of input is not changing. How can I search posts after typing 3 symbols if I cannot get input.value.length? Also how can I search without refreshing a page? I know that it can be done with ajax but I got this code and it does nothig, page is still reloading after submit:

JavaScript

Advertisement

Answer

Your input value isn’t changing because you are listening for ‘submit’ event on form. You should create a listener on input element on ‘input’ event.

JavaScript

Inside you should create yourself a check in which the function will return and do nothing if value is shorter than 3 symbols.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement