title: Accessing WordPress user meta array values
body: <p>Here is what I am using to retrieve some custom user meta in WordPress:</p>
  
  <pre><code>$user_id = get_current_user_id();
  $key = 'submit_data_' . $cat;
  $single = true;
  $viewed = get_user_meta( $user_id, $key, $single );
  </code></pre>
  
  <p>And <code>var_dump($viewed);</code> returns this:</p>
  
  <pre><code>array(2) { 
  ["catalog_number"]=&gt; string(6) "VIZ025" 
  ["sub_date"]=&gt; string(19) "2015-09-29 06:40:18" 
  }
  </code></pre>
  
  <p>When I try to access the values using <code>$viewed["catalog_number"]</code> I get an illegal offset warning which I understand but then using something like <code>$viewed[0]</code> returns nothing.</p>
  
  <p>How do I access the values e.g. "VIZ025" and the date string? </p>
  
  <p>I need to use the values in some conditionals like this:</p>
  
  <pre><code>&lt;?php if($viewed["catalog_number"] == $cat) { 
   // stuff here
  } ?&gt;
  </code></pre>
  
  <h2>Updated</h2>
  
  <p><code>var_dump($viewed, $viewed['catalog_number']);</code> returns this:</p>
  
  <pre><code> array(2) { ["catalog_number"]=&gt; string(6) "VIZ025"
  ["sub_date"]=&gt; string(19) "2015-09-29 06:40:18" } string(6) "VIZ025"
  </code></pre>
  
  <h2>Solved</h2>
  
  <p>I needed to use isset as new visitors would not have this in the user meta tables yet:</p>
  
  <pre><code>if (isset($viewed['catalog_number'])) {
   $ccat = $viewed['catalog_number'];
  }
  </code></pre>
  
  <p>This is a valuable lesson: always make sure there is a value to access.</p>