1

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

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?

I've got it working as follows:-

function apply_for_job() {

    if (!empty($_GET['job_id'])) {
        $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);


}
if (!empty($_GET['job_id'])) {
add_filter('init' ,'apply_for_job');
}

Although this is probably not the 'standard' way

  • Not sure what the big picture is, but note that you're running this on every page load (front-end and back-end) even when there's no job_id GET parameter. Your $prev_value is also not used. – birgire Jan 28 '16 at 16:20
  • I've got it working @birgire - although I'm sure this isn't the correct way in doing this – nsilva Jan 28 '16 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.