• I have a function that constructs an author byline from an array of taxonomies with get_the_terms. I see PHP Notices in my logs…

    Notice: Array to string conversion ... wp-includes/taxonomy.php on line 3255

    and

    Notice: Array to string conversion ... wp-includes/category-template.php on line 1245

    Here is the code:

    function my_byline() {
      $tax = array( 'my_staff', 'my_contributor' );
      // Get the authors by term ID
      $terms = get_the_terms( get_the_ID(), $tax );
      // Count the terms
      $count = count( $terms ); $i = 0;
      // Check if authors are in array
      if ( is_array( $terms ) ) {
        $byline = '<span>';
        // Loop through authors and build the $byline
        foreach ( $terms as $term ) {
          // Author ID
          $tid = $term->term_id;
          // Author object
          $author = get_option( 'taxonomy_'. $tid );
          // Author iterate
          $i++;
          // Author byline
          $byline .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all resources by %s', my-byline' ), $term->name ) . '">' . ( isset( $author['first_name'] ) ? $author['first_name'] : '' ) . ' ' . ( isset( $author['middle'] ) ? $author['middle'] : '' ) . ' ' . ( isset( $author['last_name'] ) ? $author['last_name'] : '' ) . '' . ( $author['suffix'] ? ', ' . $author['suffix'] : '' ) . '</a>' .
          ( isset( $author['status'] ) && $author['status'] == 'former' ? ' <em style="color:#999;">(Former Staff)</em>' : '' );
          // Add a comma if more than 1 author is found
          if ( $count != $i ) $byline .= ', '; else $byline .= '</span>';
        }
        // Output
        return $byline;
      }
    }

    WP: 3.9.2
    PHP: 5.4.29

    Do you see anything wrong with this code? Help fix?

    Thanks

The topic ‘get_the_terms taxonomy Array to string conversion’ is closed to new replies.