0

I am writing a filter. Here is the scenario... it's for a website selling yoga retreats. I have successfully created a new meta profile field called "retreat_contracts" which is meant to store the liability waivers a given user has completed.

There's only one piece that's not working. For some reason, get_user_meta is not returning a value. I have double and triple-checked the meta field key, and it is 'retreat_contracts' without a doubt. I can also verify that 'retreat_contracts' is NOT empty in my profile or database (it's currently mostly curse words), so $current_contracts should have that value, right?

$current_contracts =  get_user_meta( $user_id, 'retreat_contracts', TRUE);
if (empty($current_contracts)) {
    // DO THIS STUFF
} else {
    // DO THIS STUFF
}

It should be operating the "else" stuff, but it's not.

Any insight? I am sure there's something obvious I'm missing, but I've been looking at it for two days, and I just can't figure it out.

  • Firstly, try if (!$current_contracts)... Secondly, are you storing a string or array there? Please echo/var_dump() it in both scenarios to check the problem. This is the best way to find out what the problem is, like a misspell... – Christine Cooper Jun 2 '15 at 16:20
  • Thanks for responding. Part of the code I didn't include (for purposes of streamlining my question) was assigning the value of $current_contracts to my user field 'retreat_contracts'. I did echo the value of $current_contracts, and it shows up as empty/blank. – NYCjbd Jun 2 '15 at 17:49
0

I can confidently say that it is empty at the point at which your code checks the variable. The three possibilities are:

  1. $user_id is not set or is set to an incorrect value. As you don't show the code that sets this value, I can't tell.
  2. You are using the wrong key.
  3. Something is hooked into get_user_metadata and is causing a problem.

While I am not 100% sure, I am fairly sure that those are an exclusive list.

If you can post your code with more context I might be able to do better.

  • OHMIGOSH. THANK YOU! I am such a doofus. I'd been looking at this for days, and I'd just failed to set $user_id. HA! I knew it was something like that. I need to get these glasses checked. – NYCjbd Jun 2 '15 at 17:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.