How to use wp_update_post with ajax on frontend

hmmm…. I don’t see a problem with your code. When I run into 500, it’s usually due to permissions or htaccess mis-routing the request. That said, some things to try: 1) in wp-config.php, set debug WP_DEBUG to true. This may offer a more descriptive error message. 2) WordPress has good integration for AJAX. You can … Read more

How can I use AJAX with check-box categories?

You’ll need to hook into the “onchange” event of javascript. When using jquery, it’s as simple as $(‘<the selector string>’).change(function(){}); When ever the values are changed, you’ll do an AJAX request to the server with the new parameters & populate the output screen with the new result. For the server-side, you’ll check the parameters, do … Read more

AJAX function not working [closed]

You have an error on this line: var appendHTML = ‘<div class=”ajax-loading-screen appended”> Be careful with multi-line string in Javascript. It doesn’t work the way it does in PHP. https://stackoverflow.com/questions/805107/how-to-create-multiline-strings

Something strange with ajax

add_action and add_filter always return true. And yes, in PHP, any string that is not empty or “0” is loosely equal to the boolean true. And I see nothing wrong with your die code. It’s hooked to wp_ajax_my_action, so you need to make a call to the admin-ajax.php as an authenticated user, with the my_action … Read more

need a confirmation text to appear on email submission

Simply add a Success callback to your Ajax function: $(‘#sendEmail’).click(function(){ $.ajax({ type: ‘POST’, url: ‘www.example.com/email.php’, data: { content: $(‘#email-data’).html()}, success: function(data) { //data variable can be used if your ajax call returns something do_stuff_here(); } }); }); In your case, you could do something like success: function() { $(‘body’).append(‘<div class=”success”>Success!</div>’); } However, is there a … Read more

Change post query onclick

Yes, if you need to run WordPress/PHP functions from a button click (Javascript), you need Ajax. In the following example, a shortcode will render a button (id=”newquote”) that calls an Ajax action hook (get_random_cpt). A query is done and replaces one div from that shortcode (id=”randomquotes”) with the results. How to Use Ajax in a … Read more

problem using ajax url

You should use the WP AJAX APIs rather than reinventing them in your home template, e.g.: functions.php : // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( ‘my-ajax-request’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); add_action(‘wp_ajax_my_action’, ‘my_action_callback’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action_callback’); function my_action_callback() { $content=”something to send back to the … Read more