I am trying to use the below code snippet to display an image and then wrap it in a link to a specific term archive page. In this case, I have a custom taxonomy (Series) with a few different terms. The variable $series outputs the Term Object, therefore I want to use the get_term_link function to get the URL to the terms archive page.

The documentation for get_term_link (http://codex.wordpress.org/Function_Reference/get_term_link) says that I should simply be able to provide the term object and it will work, but it's not. I'm getting a partial-page load, meaning the code is breaking when it reaches this function.

Any help is appreciated!

$imageid = get_sub_field('series_banner', 'options');
$image = wp_get_attachment_image( $imageid, 'home-series-banner');
$series = get_sub_field('series_link', 'options'); //Returns the term object ?>
<a href="<?php echo get_term_link($series); ?>"><?php echo $image; ?></a>

2 Answers 2


That field can return multiple term objects depending on how you've got it configured, so I'll guess that $series in this case is an array containing a single element, which contains your term object. Try inspecting the contents of series:

print_r( $series );

You'll probably see something like:

    [0] => stdClass Object
            [term_id] => 1
            [name] => test
            [slug] => test
            [term_group] => 0
            [term_taxonomy_id] => 1
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 1

If this is the case, try passing $series[0] to get_term_link.

  • Thanks for the help. It turns out the plugin (Advanced Custom Fields) that I'm using to save and return the ID has a bug that is causing this. So my code above will work once that bug is fixed. I'll mark this as the answer though, as it's a good troubleshooting process for others.
    – Eckstein
    Commented May 14, 2013 at 16:06

The problem is you are getting term_id as a string so convert it before function


(int)$term_id=(int)str_replace(' ', '',$data[0]->term_id);

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.