WordPress.org

Ready to get started?Download WordPress

Forums

get_term_link() Throwing Error (5 posts)

  1. pealo86
    Member
    Posted 2 years ago #

    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?

  2. pealo86
    Member
    Posted 2 years ago #

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

  3. Vrunda Pandya
    Member
    Posted 1 year ago #

    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

  4. Shail
    Member
    Posted 1 year ago #

    use $term->term_id instead $termid.

  5. bencarter78
    Member
    Posted 1 year ago #

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

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

    All working now.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags