I'm trying to connect some user_meta data from registration form to some categories set up in admin to filter the presentation on the page. This one is tripping me up because the question has multiple answers ...
Here is what I have set up so far ...
$user_id = $current_user->ID;
$user_values = get_user_meta( $user_id);
$interest_disaster = $user_values['interest_disaster'][0];
$interest_animals = $user_values['interest_animals'][0];
$interest_women = $user_values['interest_women'][0];
$interest_seniors = $user_values['interest_seniors'][0];
$interest_hunger_health = $user_values['interest_hunger_health'][0];
$interest_education = $user_values['interest_education'][0];
$interest_environment = $user_values['interest_environment'][0];
$interest_arts_culture = $user_values['interest_arts_culture'][0];
$interest_children_youth = $user_values['interest_children_youth'][0];
$interest_other = $user_values['interest_other'][0];
$interest_mentoring = $user_values['interest_mentoring'][0];
$interest_poverty_urban = $user_values['interest_poverty_urban'][0];
I can stick those in an array ...
$interestBlock = array(
$interest_disaster,
$interest_animals,
$interest_women,
$interest_seniors,
$interest_hunger_health,
$interest_education,
$interest_environment,
$interest_arts_culture,
$interest_children_youth,
$interest_other,
$interest_mentoring,
$interest_poverty_urban
);
But I am failing badly at checking if the item exists in my category array inside a function and echoing values set in $user_values
array out to page or sticking them in a custom query.
function convertInterestCategory(){
$interestCategories = array(
'interest_disaster',
'interest_animals',
'interest_women',
'interest_seniors',
'interest_hunger_health',
'interest_education',
'interest_environment',
'interest_arts_culture',
'interest_children_youth',
'interest_other',
'interest_mentoring',
'interest_poverty_urban'
);
$counter = 0;
//Stuff in usermeta
foreach ($interestCategories as $counter) {
if (in_array($interestCategories , $user_values)){
echo $user_values[$interestCategories][0];
$counter++;
}
}
}
I'd appreciate help in putting together a loop function to check if item exists in $user_values
array and is also in $interestCategories
array, then how to return relevant results. Thanks in advance.
One by one it would look like this I guess ...
//Interests
if (isset($user_values['interest_disaster'][0])){
$interest_disaster = $user_values['interest_disaster'][0];
echo $interest_disaster;
}
if (isset($user_values['interest_animals'][0])){
$interest_animals = $user_values['interest_animals'][0];
echo $interest_animals;
}
if (isset($user_values['interest_women'][0])){
$interest_women = $user_values['interest_women'][0];
echo $interest_women;
}
if (isset($user_values['interest_seniors'][0])){
$interest_seniors = $user_values['interest_seniors'][0];
echo $interest_seniors;
}
if (isset($user_values['interest_hunger_health'][0])){
$interest_hunger_health = $user_values['interest_hunger_health'][0];
echo $interest_hunger_health;
}
if (isset($user_values['interest_education'][0])){
$interest_education = $user_values['interest_education'][0];
echo $interest_education;
}
if (isset($user_values['interest_environment'][0])){
$interest_environment = $user_values['interest_environment'][0];
echo $interest_environment;
}
if (isset($user_values['interest_arts_culture'][0])){
$interest_arts_culture = $user_values['interest_arts_culture'][0];
echo $interest_arts_culture;
}
if (isset($user_values['interest_children_youth'][0])){
$interest_children_youth = $user_values['interest_children_youth'][0];
echo $interest_children_youth;
}
if (isset($user_values['interest_other'][0])){
$interest_other = $user_values['interest_other'][0];
echo $interest_other;
}
if (isset($user_values['interest_mentoring'][0])){
$interest_mentoring = $user_values['interest_mentoring'][0];
echo $interest_mentoring;
}
if (isset($user_values['interest_poverty_urban'][0])){
$interest_poverty_urban = $user_values['interest_poverty_urban'][0];
echo $interest_poverty_urban;
}