The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Show PODS User Fiel...
 
Share:
Notifications
Clear all

Limited Support

Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed.
We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.

 

[Solved] Show PODS User Fields in wpDiscuz Comment

2 Posts
2 Users
0 Reactions
262 Views
Posts: 26
Topic starter
(@gooloode)
Trusted Member
Joined: 3 years ago

Hello,

i am writing a beauty blog and i would like to show the user's skin, and hairtypes, etc. below their Name in wpDiscuz Comments.

I set up PODS and added the custom fields to the profile edit section:
I want to show the selected entries from PODS below the author's name in Comments in wpDiscuz. I've set up the PODS Plugin and added a POD to user profile > advance with the following options that i want to show below the author's name: Type Select, Single - alter - hauttyp_gesicht - hauttyp_koerper - haartyp - haarstruktur - haardicke - augenfarbe Type Select, Multiple, Checkbox - hautprobleme

Β 

I have added the following code snippet to my functions.php:

// Display PODS custom fields in wpDiscuz comments below the author's name
add_filter('wpdiscuz_comment_author_text', 'pods_profile_fields_display', 10, 2);

function pods_profile_fields_display($author_text, $comment) {
    // Get the user ID of the comment author
    $user_id = $comment->user_id;

    // Return the original author text if the user is not logged in
    if (!$user_id) {
        return $author_text;
    }

    // Retrieve PODS data for the user
    $user_pod = pods('user', $user_id);

    // Return the original author text if no PODS data is found
    if (!$user_pod) {
        return $author_text;
    }

    // Define an array of single-select fields with their labels
    $single_fields = [
        'alter' => 'Alter',
        'hauttyp_gesicht' => 'Hauttyp Gesicht',
        'hauttyp_koerper' => 'Hauttyp KΓΆrper',
        'haartyp' => 'Haartyp',
        'haarstruktur' => 'Haarstruktur',
        'haardicke' => 'Haardicke',
        'augenfarbe' => 'Augenfarbe'
    ];

    // Initialize a variable to store additional information
    $additional_info = '';

    // Loop through each single-select field and append its value if it exists
    foreach ($single_fields as $field_name => $field_label) {
        $field_value = $user_pod->field($field_name);
        if (!empty($field_value)) {
            $additional_info .= sprintf(
                '<div class="user-%s">%s: %s</div>',
                esc_attr($field_name),
                esc_html($field_label),
                esc_html($field_value)
            );
        }
    }

    // Handle the multiple-select field "hautprobleme"
    $hautprobleme = $user_pod->field('hautprobleme');
    if (!empty($hautprobleme)) {
        // Convert array to comma-separated string if necessary
        $hautprobleme_value = is_array($hautprobleme) ? implode(', ', $hautprobleme) : $hautprobleme;
        $additional_info .= '<div class="user-hautprobleme">Hautprobleme: ' . esc_html($hautprobleme_value) . '</div>';
    }

    // Append additional information to the author text if any exists
    if ($additional_info) {
        $author_text .= '<div class="user-profile-info">' . $additional_info . '</div>';
    }

    return $author_text;
}

I also added the following CSS:

/* Style for user profile information displayed in comments */
.user-profile-info {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.user-profile-info > div {
    margin-right: 10px;
    background-color: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
}

@media (max-width: 480px) {
    .user-profile-info {
        flex-direction: column;
        gap: 4px;
    }

    .user-profile-info > div {
        margin-right: 0;
    }
}

Is there anything i'm doing wrong or is there a better version to do it?

1 Reply
Asti
Posts: 8075
 Asti
Support
(@asti)
Illustrious Member
Joined: 8 years ago

Hi,

wpDiscuz doesn't have a wpdiscuz_comment_author_text hook.
Please check the full list of available wpDiscuz hooks here and choose the one that best fits your needs:

Reply
Share: