Querying Custom Taxonomy for Users in a User loop

Support MB User Meta Querying Custom Taxonomy for Users in a User loop

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #42619
    AnLipAnLip
    Participant

    I'd like to display the values of a custom taxonomy linked to each user, in a User loop.
    I am using Bricks, and have set on a container in a Page a loop for Users. So far it works good and displays them listed.
    But when I want to add below the user names the values of a custom taxonomy (taxonomy slug is "disciplines", custom field ID is "frigos_user_discipline"), I either only get the values of the logged in user (so the same below every user name, which is not good), or I get various error messages if I try to modify the query.

    So far I am using this code block (that displays the same everywhere) :

    <?php 
    $terms = rwmb_meta( 'frigos_user_discipline', [ 'object_type' => 'user' ], get_current_user_id() ); 
    ?>
    <div style="line-height: 1em;">
        <?php foreach ( $terms as $term ) : ?>
            <span class="fr--tag__discipline" style="margin-right: 1em;"><?= $term->name ?></span>
        <?php endforeach ?>
    </div>
    #42638
    PeterPeter
    Moderator

    Hello,

    Because the function get_current_user_id() returned the current logged-in user (you are) so you will see that issue. You need to replace that function with the user ID in the context or in the loop to display the user meta.

    #42642
    AnLipAnLip
    Participant

    Thank you Peter, but I don't understand what you are suggesting.
    Could you provide a code that will work inside a Bricks User query ?

    #42658
    PeterPeter
    Moderator

    Hello,

    In this case, I recommend contacting Bricks support to ask for getting the user ID in the loop/user query.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.