How to insert new element to existing array in usermeta?

Let’s analyze your code and what it does. Assuming that the current fruits stored in the database are ‘pineapple’ and ‘orange’, get_user_meta(2, ‘fruits’, false) will return something like this: array( array( ‘pineapple’, ‘orange’ ) ) This is because you passed false as the third argument, $single. The function returns an array if $single is false … Read more

Ensure function has completed before allowing another Ajax call

I usually use CSS classes to control AJAX requests affecting a specific element. This way you can prevent unwanted AJAX requests on that element, while other AJAX requests may still be triggered, being bound to other elements. $(‘.slot’).on(‘click’, ‘a.book’, function(e) { e.preventDefault(); // Check if doing ajax if($(this).hasClass(“doing-ajax”)) return false; $(this).addClass(“doing-ajax”); var user = $(‘#rjb_day’).attr( … Read more

Gravity Custom Merge Tags [closed]

You need to add the new merge tags with the gform_custom_merge_tags filter, and then replace them with the gform_replace_merge_tags filter, like this: Edit: you need to use the gform_field_content filter to replace the field’s default value, see below. add_filter(‘gform_custom_merge_tags’, ‘wpse_121476_custom_merge_tags’, 10, 4); add_filter(‘gform_replace_merge_tags’, ‘wpse_121476_replace_merge_tags’, 10, 7); add_filter(‘gform_field_content’, ‘wpse_121476_field_content’, 10, 5); /** * add custom merge … Read more

update_user_meta() does not work

You set the variable $user before you created this user.. It should be like this and you need to check if the user already exists $user = get_user_by(“email”, $email); // Its return you the user object if($user) { update_user_meta($user->ID, “quiz_scores”, $score); } else { $user_id = register_new_user($email, $_SESSION[“email”]); update_user_meta($user_id, “quiz_scores”, $score); }

Getting $user_id for the_author_meta outside the loop in multisite

Not sure how this would differ with multi-site, but this is how you’d do this outside the loop normally: <?php # get post data $temp_post = get_post($post_id); # grab the author meta $user_id = $temp_post->post_author; # grab the field you’re looking for $first_name = get_the_author_meta(‘first_name’,$user_id); # display field echo $first_name; ?>

Multiple User-Meta Values in One User-Meta Key

If you check out the documentation for the update_user_meta() function, you’ll note that the $meta_value parameter already accepts objects and arrays, so you can simply save a user’s positions in an array without any additional effort: update_user_meta( 22, ‘position_names’, array( ‘Khaleesi of the Great Grass Sea’, ‘Breaker of Chains’, ‘Mother of Dragons’ ) ); The … Read more