I have a form on my website where users can submit their own posts and one of the fields has a dropdown containing various countries so a user can enter their location. I would like this location to be displayed when the post is published so I have written the below code to achieve this:

<?php echo stripslashes(get_user_meta($uid, 'user_location', true)); ?>

However, this only displays the category "ID" number (not the category "name" of the location). What can I write so the NAME of the location is displayed?

  • Is there an easy way to display the LOCATION BY NAME (rather than ID NUMBER)? I have included the code that was used for the page where the form is: <?php $locs = get_user_meta($uid, 'user_location', true); echo PricerrTheme_get_categories("job_location", !isset($_POST['job_location_cat']) ? $locs : htmlspecialchars($_POST['job_location_cat']) , __('Select Location','PricerrTheme'), "do_input"); ?> </p> – Sam Apr 3 '15 at 19:15

Use get_category() to convert the ID into a category data object.

$cid = get_user_meta($uid, 'user_location', true);
$c = get_category($cid);
echo $c->name;
  • That didn't work unfortunately. If it helps, the taxonomy = "job_location" when I hover over the category name. And "job_location_cat" is also mentioned in the code. – Sam Apr 3 '15 at 18:38
  • You called this a "category" but you may need get_term() instead. – s_ha_dum Apr 3 '15 at 18:43

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.