Home › Forums › Front-end Issues › Relationship field in BBpress forum post › Reply To: Relationship field in BBpress forum post
Solved my own question playing off @jaybuys. Since the relationship field on all user edit screens (wp/bbp) all we need to do is call it on the profile page. I have hooked into the after the user profile and am showing the related posts.
add_action('bbp_template_after_user_profile', 'bbp_show_extra_fields');
function bbp_show_extra_fields() {
$topic_id = get_user_by( 'slug', get_query_var( 'author_name' ) );
if ( function_exists('get_field') && get_field('relationship_field', $topic_id) ) {
$related_posts = get_field('relationship_field', $topic_id);
foreach ($related_posts as $related_post) {
if (get_post_status( $related_post) == 'publish') {
echo '<a href="' . get_permalink( $related_post) . '" class="btn">' . get_the_title( $related_post) . '</a>';
}
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.