Here is what I am using to retrieve some custom user meta in WordPress:
$user_id = get_current_user_id();
$key = 'submit_data_' . $cat;
$single = true;
$viewed = get_user_meta( $user_id, $key, $single );
And var_dump($viewed);
returns this:
array(2) {
["catalog_number"]=> string(6) "VIZ025"
["sub_date"]=> string(19) "2015-09-29 06:40:18"
}
When I try to access the values using $viewed["catalog_number"]
I get an illegal offset warning which I understand but then using something like $viewed[0]
returns nothing.
How do I access the values e.g. "VIZ025" and the date string?
I need to use the values in some conditionals like this:
<?php if($viewed["catalog_number"] == $cat) {
// stuff here
} ?>
Updated
var_dump($viewed, $viewed['catalog_number']);
returns this:
array(2) { ["catalog_number"]=> string(6) "VIZ025"
["sub_date"]=> string(19) "2015-09-29 06:40:18" } string(6) "VIZ025"
The string(6)
looks like it is part of the value which is why I'm getting the warnings. So I need to grab just what is in quotes.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire