Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

bulk update meta value with ajax

After click on <a> tage send an ajax request. I will write only php code do jQuery part yourself.

<script type="text/javascript" >
    jQuery(document).ready(function($) {

    var data = {
        action: 'my_action'
    };

    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    $.post(ajaxurl, data, function(response) {
        //Do watever after you get response
    });
});
</script>

In Your function.php

add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );
function my_action(){
    global $current_user;
    get_currentuserinfo();
    $userid = $current_user->ID; //You can also user get_current_user_id() to get current user id
    $args = array(
        'posts_per_page' => '-1',
        'post_type' => 'answer',
        'post_status' => 'publish',
        'author__not_in' => $userid, //exclude user posts
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'question_owner_id'
                'value' => $userid, //only show posts for the user
                'compare' => '='
            ),
            array(
                'key' => '_read_answer'
                'value' => 'unread', //only show unread posts
                'compare' => '='
            ),
         )
    );
    $questions = new WP_Query( $args ); //Get all the post whose meta you want to update
    foreach($questions->posts as $question):
        update_post_meta( $question->ID, '_read_answer', 'read' ); //Update all the posts meta.
    endforeach;
    echo true; //Send the response. You can aslo send response whatever you want.
    die();
}

When ever some one click on a tag it will send an ajax request to the server. The server run the previous code to get posts whose meta you want to update. After getting the post update their meta value.

Related Posts:

  1. Long Polling: Stuck in while loop
  2. How to update Comment post meta through an Ajax call
  3. Update attachment metadata fails
  4. Attach time/date stamp on add_post_meta
  5. Update status, meta while inside a post using AJAX button
  6. Filter images from media library by guid meta field
  7. Want to send ajax request in wordpress to a custom file in plugin
  8. delete post meta data in array WordPress
  9. Allow guest to update custom post met using ajax
  10. Data from ajax not updating post meta
  11. delete attachment for one post without deleting actual attachment post
  12. Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
  13. JavaScript implementation of Gzip
  14. How to cache json with wp-super cache
  15. WordPress AJAX with Axios
  16. Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
  17. Get Previous & Next posts by Post ID
  18. Nonces and Cache
  19. REST API endpoint for elasticpress autosuggest
  20. ajax – why multiple calls to wp_create_nonce() return same value?
  21. AJAX request on the frontend always returns 0 if user is not admin
  22. Admin Notification after save_post, when ajax saving in gutenberg
  23. Using ajax on categories and wordpress loops
  24. Cannot load admin-ajax.php. No access-control allow origin*
  25. Initialize JS with an ajax loaded ACF form
  26. WordPress Nonce Issue for Ajax Login and Logout
  27. How to modify wp_ajax function?
  28. Nonces and Ajax request to REST API and verification
  29. Vue.js + AJAX Shortcode
  30. Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
  31. wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
  32. Can’t seem to get wp_localize_script to work
  33. wp_ajax action is not running
  34. Ajax – gettext without a plugin
  35. WordPress AJAX calls not detecting language properly?
  36. AJAX issue – Uncaught SyntaxError when processing Zip File
  37. wp_verify_nonce doesn’t return true on server when it matches the nonce
  38. update_user_meta doesn’t work with AJAX
  39. How do I set the url to make an ajax request for a html document?
  40. wp-admin AJAX with Fetch API is done without user
  41. Ajax stops working when logged in?
  42. WordPress ajax get content post id
  43. Using wp_handle_upload and media_handle_sideload with ajax
  44. Populating content dynamically via AJAX and Advanced Custom Fields [closed]
  45. Create Page With wp_insert_post() and AJAX
  46. Load ajax if is_home()
  47. How to know what page is calling admin-ajax.php?
  48. Populate a Map at The Same Time as showing Posts via AJAX
  49. wp_localize_script not working on ajax response
  50. Get wp_title wp ajax
  51. Why Does WordPress not output admin-ajax.php path by default?
  52. Ajax custom search not functioning as expected
  53. Jetpack Infinite Scroll – Add more than 7 posts each time?
  54. SSO autologin WordPress + Ajax
  55. Speed/Performance difference between `wp_ajax` and `init` checks for AJAX/POST requests?
  56. Test WordPress api with postman
  57. How to handle 400 status in Ajax [duplicate]
  58. Remove trailing 0 from function that is used both statically and dynamically
  59. How to process wordpress ajax call without action parameter?
  60. How to load next and previous posts by Ajax
  61. Nonce fails on ajax save
  62. WordPress ajax works on FF but not on IE & chrome
  63. Disallow second login session
  64. WordPress P2 live problem
  65. All AJAX requests return a 400 error
  66. Unable to successfully verify nonce
  67. Create custom POST Method URL
  68. Getting a variable using $post ajax back from php to js response in WP
  69. AJAX Call – Failed to load resource: the server responded with a status of 500 (Internal Server Error)
  70. WordPress is Not Setting PHP $_POST on Custom Ajax
  71. AJAX jQuery post frontend returning failed to load resource status 400
  72. ajax form is returning the dreaded “[HTTP/1.1 400 Bad Request” and a zero
  73. wp_query with ajax
  74. How to check nonce lifetime value of plugins?
  75. How can I wp_send_json data?
  76. Making POST request with AJAX returns a 400 error (without jQuery)
  77. PHP session when called wp_ajax_nopriv
  78. AJAX – SHORTINIT set to TRUE returns blank
  79. How to make image in TinyMCE clickable
  80. How to use Jeditable plugin with admin-ajax.php?
  81. Uncaught TypeError: Cannot read properties of undefined (reading ‘message’) [closed]
  82. Disabling ajax code that does a POST request that ends in a 400 error code
  83. How to prevent my external API call from being called by anyone but me (my site)
  84. get a bad request 400 on my ajax-admin.php file
  85. Registration form AJAX check for existing username (simple version)
  86. Trigger action via button
  87. Syntax error on query_vars while handling with Jquery
  88. How to send the checkbox value to email
  89. Remove item from post_meta array via AJAX
  90. Sending email with wp_email and AJAX
  91. AJAX Call in Plugin Returns More than JSON
  92. Ajax Form seems to post, but does not return
  93. Why can wordpress not find the actions I add in my constructor?
  94. Memberpress isn’t cooperating with WooCommerce
  95. where does my function output from load-* go?
  96. Facebook Pixel + WooCommerce + AJAX = Confusion
  97. Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
  98. Use Ajax to get an Options Settings Value
  99. Run PHPMailer function after ajax function completes that adds row to custom table
  100. wordpress filter for searching categories with ajax not working
Categories ajax Tags ajax, post-meta
Save WYSIWYG editor plugin settings, only works after second save
Pods CMS – Get ACT’s attached image records by auto-id?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress