Forum post author meta display

I need do display some extra user meta on the forum posts next to the author avatar. I colected the meta the key is industry_stance. in forums.php line 1454 i can see where it needs to be, just cant show that data. any ideas? also is there a away to make customizaions that wont be overwritten by updates? Thanks

  • Hoang Ngo

    Hi @badmonkeycircus,

    I hope you are well today.

    Yes, the code you mentioned is the code we will be modifying. I assume that your users accounts already have the key 'industry_stance' in the usermeta table.

    Firstly, please find the code

    if ($tmp_blog_id == ''){
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) . '</p></td>';
    			} else {
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) . '</p></td>';
    			}

    On line 1453

    And then, please append this code before the code above
    $custom_content = get_user_meta($tmp_post['post_author'],'industry_stance',true);

    This code will be get the user meta from post author, you can customize it for adding some html elements to fit your design.

    And after that, please update the code

    if ($tmp_blog_id == ''){
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) . '</p></td>';
    			} else {
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) . '</p></td>';
    			}

    To

    if ($tmp_blog_id == ''){
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) . $custom_content. '</p></td>';
    			} else {
    				$content =  $content . '<td class="forum-post-author"' . $style . ' width="20%" style="text-align:left" ><p style="padding-left:10px;"><a name="post-' . (int)$tmp_post['post_ID'] . '" id="post-' . (int)$tmp_post['post_ID'] . '"></a>' . esc_html(forums_author_display_name($tmp_post['post_author'])) . '<br />' . get_avatar( $tmp_post['post_author'], '48', get_option('avatar_default') ) .$custom_content . '</p></td>';
    			}

    And now, the new meta key will display beside the avatar.

    If you have any issues please don't hesitate to let us know so we can assist.

    Best Regards
    Hoang