WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to update some user meta information from the front end of a WordPress page when the user clicks on a button. I am attempting to pass along a string of data, and then updating the field when the data is passed to the php file.

This is the code I have, but the data is not being updated on the user profile page.


jQuery(document).on('click', ".removeFav", function() {

    var item = '#'+jQuery(this).parent("div").attr("id");
    jQuery(item).remove(item); //visually remove item from product list

    // AJAX call to remove item
        url: '<?php echo get_template_directory_uri(); ?>/my-product-delete.php', //using data-slug value to specify unique product id + data-category for tab category (so item isn't deleted across all tabs if there are duplicates)
        type: 'post',
        data: { 'action' : 'change_json_favoriteString', 'id' :  jQuery(this).parent("div").attr("data-slug") , 'category' :  jQuery(this).parent("div").attr("data-category") },
        dataType: 'json',
        success: function(data) { 
        error: function(data){



    $thisProductID = $_GET['id'];
    $thisProductCategory = $_GET['category'];

    /* Get current user info */

    $currentUserID = $current_user->ID;

    $currentUsersFavorites = $current_user->json_favorites;

    $newJSONfavorites = 'http://wordpress.org'; // <= must create a dynamic variable to populate with new favorites json object
    update_user_meta($currentUserID, 'json_favorites', $newJSONfavorites); // <= update users json favorites with new json object

share|improve this question
What have you done to debug this? – s_ha_dum Dec 8 '13 at 2:25
You got the wrong ajax url: it should point to wp-admin/admin-ajax.php and not to my-product-delete.php'. also there are other things you are doing wrong here. check this tutorial for the right way wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress – Maruti Mohanty Dec 8 '13 at 7:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.