Tag Info

Hot answers tagged

3

I'm surprised it's all that slow but you can remove all but one of the database calls & most of the looping by passing the term data instead of just slugs to my_dropdown_categories() so get_terms() doesn't have to be called, plus a few other improvements (see comments) eg: function my_dropdown_categories( $taxonomy, $current_selected = '', $terms = ...


3

You don't have to specifically enqueue jQuery, as you're probably using jQuery in your custom script. You can do: wp_enqueue_script( 'my-script', plugin_url( 'js/my-script.js', __FILE__ ), array('jquery') ); jQuery(document).ready(function($){ //Do anything... }); Notice the $ passed as an arg to the callback, it will make jQuery accessible to your ...


2

I have been investing some quality time (and headaches) with WP ajax so I understand where you are coming from. In all honesty, it could be anything from an error in your JS code or something completely bizarre, like: add_action('wp_ajax_UpdateMeta', 'UpdateMeta'); Should be changed to: add_action('wp_ajax_updatemeta', 'UpdateMeta'); ... to remove ...


2

You are not enqueueing your custom JavaScript file. And calling the var (templateUrl) in JS file without the handle. Follow the following: I'm enqueueing my custom JavaScripts file (script.js) under the dependency of jQuery, so it will enqueue jQuery library from core. And I'm using the same handle my-custom-js for both my script and localize_script to pass ...


1

To do that you will first have to deregister your jQuery script and then register again. If you use jQuery comes with WordPress then following is the function your are looking for. function starter_scripts() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true ); ...


1

Updating the url via javascript, is not related to WordPress, however you just need to modify window.location.hash in your jQuery code. Regarding the usage of admin-ajax.php it is recommended way to do tasks via AJAX that need to load WordPress environment, instead of manually requiring wp-load.php. In your case you are sending a request to a regular ...


1

The difference between the code you linked and your version, is that your post link has the permalink as the href value, where the original has just a hash. When you add a click handler to an anchor tag, it doesn't prevent what normally occurs when you click that link, it just executes the javascript and normal link behavior continues as it otherwise would. ...


1

Add data-post_id attribute to checkbox and fill it with corresponding post ID. On click on compare button (link) retrieve all post ids from checked checkboxes with JavaScript (jQuery) Redirect to the comparision page with post IDs in url as GET parameters. This is just one scenario how you task could be done. PS your question is not related to WordPress ...


1

You have to use the admin-ajax handler to do the AJAX call. Replace file.php in var url = "file.php"; with yoursite.com/wp-admin/admin-ajax.php?action=simple_ajax And in your plugin / functions.php file, add add_action('wp_ajax_nopriv_simple_ajax','process_simple_ajax' //for non logged in user add_action('wp_ajax_simple_ajax','process_simple_ajax' //for ...



Only top voted, non community-wiki answers of a minimum length are eligible