1

I'm trying to display the taxonomy slug from the term ID, thus my current code is like so:

<?php $catinfo = get_category(array_pop(get_sub_field('sector_selector'))); ?>
<?php print $catinfo->slug; ?>

which isn't printing anything, a var_dump($catinfo); produces the following:

array(1) { [0]=> int(59) }

In theory <?php print $catinfo->slug; ?> should print the taxonomy slug, but it isn't? Any suggestions would be greatly appreciated!

1 Answer 1

2

You can use get_term_by() for this

<?php
$term_id = array_pop(get_sub_field('sector_selector'));
$catinfo = get_term_by( 'id', $term_id, 'name_of_the_taxonomy' );
print $catinfo->slug;
4
  • and how would this be implemented in the example above? As I can't seem to get it to work? Commented Aug 17, 2014 at 20:09
  • @user1374796 I have edited my answer, I am assuming that array_pop(get_sub_field('selector_selector')) returns term id as per your question.
    – sakibmoon
    Commented Aug 17, 2014 at 20:15
  • yes this is what I did, but I keep getting Missing argument 3 for get_term_by() etc etc, error message. I'm not sure why? Commented Aug 17, 2014 at 20:16
  • @user1374796 You have to give the name of the taxonomy as the third argument.
    – sakibmoon
    Commented Aug 17, 2014 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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