Use AJAX in a WordPress Plugin to Get Data From Custom Database?

You can use like this for send ajax… function my_action_javascript() { ?> <script type=”text/javascript”> jQuery(document).ready(function ($) { var data = { ‘action’: ‘my_action’, ‘whatever’: ‘1’ }; $.post(ajaxurl, data, function (response) { if ($(‘#menu_order’).val() == ” || $(‘#menu_order’).val() == ‘0’) $(‘#menu_order’).val(response); }); }); </script> <?php } add_action(‘admin_footer’, ‘my_action_javascript’); function my_action_callback() { $whatever = intval($_POST[‘whatever’]); //$whatever += … Read more

ajaxt returning object object [closed]

The issue is with this line: wp_localize_script( ‘ajaxHandle’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin_ajax.php’ ) ) ); It should be admin-ajax.php instead of admin_ajax.php.

Distinguish between 2 instances of admin-ajax.php

There isn’t much point to distinguishing admin-ajax.php since it’s essentially same file with same logic running for many many purposes. You are passing action data and hooking into respective action. So action is your identifier. If you are reusing same action and need to further differentiate — just pass more data with your GET/POST request … Read more

WP_query is not returning the expected result

Try using this: $args = array( ‘post_type’ => YOUR_POST_TYPE, ‘meta_query’ => array( array( ‘key’ => ‘_wpcf_belongs_marque-type_id’, ‘value’ => $parent_id ) ) ); In your loop set an else statement just to sure that you query isn’t returning zero results: if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $output .= ‘<li class=”active-results”>’ . … Read more

WP AJAX API with JS file

Currently I’m assuming that is is backend (front end is slightly different), but it’s very easy to implement on the frontend if required. You are correct in thinking that because you haven’t used the WordPress admin-ajax.php file, all the goodness of WordPress is missing. Fortunately this is easily fixed. Before continuing I recommend that you … Read more

Search query with Ajax

This is a javascript issue. You have to prevent form submission to stop the page from reloading. See event.preventDefault() in jQuery docs. jQuery(“#Submityourskill”).click(function(event){ event.preventDefault(); // the rest of your code });