Title: WordPress &#8211; Update User Profile function
Last modified: August 31, 2016

---

# WordPress – Update User Profile function

 *  [naysilva](https://wordpress.org/support/users/naysilva/)
 * (@naysilva)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wordpress-update-user-profile-function/)
 * I have the following function in my functions.php file:-
 *     ```
       function apply_for_job() {
   
           $job_id = $_GET['job_id'];
   
           $user_id = get_current_user_id();
           $prev_value = get_field('applied_jobs');
   
           update_user_meta($user_id, 'applied_jobs', $job_id);
   
       }
       add_filter('init' ,'apply_for_job');
       ```
   
 * When I load: [http://distinct.dev/apply_for_job/?job_id=323](http://distinct.dev/apply_for_job/?job_id=323)
 * This updates ‘applied_jobs’ field to: 323 as expected.
 * However, when I go on my user profile page it sets the value to ‘NULL’
 * Any ideas why?

Viewing 1 replies (of 1 total)

 *  [stirrell42](https://wordpress.org/support/users/stirrell42/)
 * (@stirrell42)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wordpress-update-user-profile-function/#post-7000448)
 * naysilva,
 * My guess is that this is happening because the apply_for_job function is running
   on every page and, unless set in the query string, the value for $_GET[‘job_id’]
   is not not set (null). So, when going to the user profile page $_GET[‘job_id’]
   is null and the user meta data is updated accordingly. I think you will want 
   to make sure the GET[‘job_id’] is not empty:
 *     ```
       if (empty($job_id)) :
       update_user_meta($user_id, 'applied_jobs', $job_id);
       endif;
       ```
   
 * Since this variable is being passed in the query string which someone with bad
   intentions could modify, you might want to consider sanitizing the variable. 
   Maybe something like:
 *     ```
       $job_id = intval($_GET['job_id']);
       ```
   
 * This tells PHP to cast the value as a number to help prevent people putting in
   things like text attempting to inject SQL or other things.
 * I hope this helps!
    Scott

Viewing 1 replies (of 1 total)

The topic ‘WordPress – Update User Profile function’ is closed to new replies.

## Tags

 * [20q2016](https://wordpress.org/support/topic-tag/20q2016/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [stirrell42](https://wordpress.org/support/users/stirrell42/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/wordpress-update-user-profile-function/#post-7000448)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
