WordPress.org

Support

Support » Themes and Templates » get_term_link() Throwing Error

get_term_link() Throwing Error

  • I am using the following code to get the ID number of a term:

    <?php
    	$terms = get_the_terms( $post->ID, 'parent-company' );
    	if ( $terms && ! is_wp_error( $terms ) ) :
    		$parentCompany = array();
    		foreach ( $terms as $term ) {
    			$termId[] = $term->term_id;
    		}
    		$termId = join( ", ", $termId );
    ?>

    The value of $termId in this case is just ’70’. And I’m trying to use it like so:

    <li><a href="<?php echo get_term_link($termId, 'parent-company'); ?>">View Franchisees:</a></li>

    However it gives the following error:
    Catchable fatal error: Object of class WP_Error could not be converted to string in...

    Whereas if I try :
    <li><a href="<?php echo get_term_link(70, 'parent-company'); ?>">View Franchisees:</a></li>

    Then it works fine! Does anyone know what I might be doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Never mind, I fixed it with:
    <li><a href="<?php echo get_term_link(intval($termId), 'parent-company'); ?>">View Franchisees:</a></li>

    Hi have same problem, and i try with this solution but it’s not work for me 🙁 it shows Catchable fatal error: Object of class WP_Error could not be converted to string in /home/jatc

    Shailesh

    @shaileshsavaliya

    use $term->term_id instead $termid.

    I was just having the same error but I changed it to

    get_term_link($term->slug, $term->taxonomy)

    All working now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_term_link() Throwing Error’ is closed to new replies.