1

I've setup my plugin to be used on the frontend using a shortcode. I have managed to use an autocomplete form on a previous website I programmed from scratch (not WP based) but I don't understand how to make it work on WP 4.0.

I have this form to allow my clients to add their own customers:

<form method="post">
<div class="pure-g">
        <div class="pure-u-1 pure-u-md-1-3">
            <label>Name</label>
            <input name="name" id="name" type="text" placeholder="Name" required>
        </div><input type="submit"></form>

To avoid different users entering the same person twice, I need an autocomplete dropdown to get results from a MySQL database (custom table) to show the user the %LIKE% result.

What I don't understand is:

  • To call the jQuery, do I have to call it from the main plugin file or on each file I setup?
  • Then, how do I use it?
  • So, your problem is how to load jQuery and scripts in general? I don't fully understand your question. – cybmeta Feb 16 '15 at 7:57
  • There are a couple of questions about autocomplete. One actually is by me (click my name, search my questions). – kaiser Feb 16 '15 at 12:06
1

Please refer to wp_script_is( $handle ) to check if a script is already enqueued or registered.

It's a good idea to check before registering / loading a new script in WordPress. Since jQuery is included with WordPress and assuming you're already using a custom WordPress theme I'm going to say it's most likely already loaded.

You could check this by checking the "resources" tab on your browser (the Scripts folder) with your website opened.

Even simpler, you could check that jQuery is loaded on your website by going to the Console tab and typing in: jQuery(); - if that' returns something, it means it's already loaded.

I think, and correct me if I'm wrong, your problem is that you don't actually know where to place your JS code for the autocomplete part. If that's the case (your question was a bit ambiguous), please answer here so we can point you in the right direction.

Thanks.

  • Yes, you got my problem. I'm at loss about where to place the js script and where to load them. Can you be of any help? Thank you all for your time – Fabrizio La Racca Feb 17 '15 at 12:14
  • Create a new folder inside your wp-content/themes/{current-active-theme-name} called js. Inside this newly created folder, create a file called autocomplete.js, place all your code in autocomplete.js Locate the functions.php file insider your {current-active-theme-name-folder} and follow these instructions from the Codex: codex.wordpress.org/Function_Reference/wp_enqueue_script – cristian.raiber Feb 17 '15 at 12:38
  • I'd prefer not to interfere with the theme and rather do it within the plugin. In the console tab I get this: []. – Fabrizio La Racca Feb 22 '15 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.