Support

Account

Home Forums General Issues List of Users – Filtered by an ACF field

Solved

List of Users – Filtered by an ACF field

  • Hello,

    Our WP users all belong to a local “Club”. The goal is to have a section on the website that displays each club and also lists all users that are associated with that particular club.

    I have not been successful in displaying a filtered user list based on their club affiliation, I only seem to be able to display the entire user list.

    For the Club listing, I have a Custom Post Type and also a group of ACF fields that accept details, such as location and contact information. That part is working fine!

    To associate WP users with those clubs, I have set up an ACF relationship field. The field is programmed to display on the User’s form so that I can go to any user and select the club that they belong to. This is also working fine!

    The problem comes in when I try to display a list of filtered users.

    My current approach is to use a widget called Dynamic Users made by Dynamic OOO. It allows for user display and filtering by criteria such as “User Field Filters” and “Meta Value”. In the “User Field Filters,” it successfully finds my ACF relationship field, but it does not filter the list.

    Any ideas on how to troubleshoot this?

  • That depends on what the other plugin is expecting to see in the custom field. An ACF relationship field stores an array of Post IDs. In the DB this is stored as serialized data.

    When you do a reverse relationship query, which is what you need to do in PHP to get all the users associated with a post you need to do a LIKE query on the value "{$post_id}" (note the “s). So the plugin needs to be able to look for values that are “LIKE” the value you are looking for rather than exactly equal to.

  • Hi John,

    Your information helped me solve my problem. I am very grateful!

    If others are looking to do a similar thing, here are the specifics on what I did to display a list of users filtered by custom criteria.

    Set up an ACF relationship field, set to show up on each user’s edit page.
    Update some of your users to provide data to work with.
    Plugin= Dynamic OOO. They have several dynamic tools, but the Views tool worked for this purpose (this tool is flexible and powerful). I struggled with their Dynamic Users tool for a long time until I realized that it couldn’t do the type of query I needed.
    Create or Edit the page in Elementor and drag the “Views” tool onto your page.
    In the settings under Object, click on the Users icon (the middle one).
    In the Where – Filter criteria settings, set the filter to the name of your ACF relationship field. Also, set the Operator to “LIKE” and in Value, choose “Post ID” from the dropdown.

    To see your result, in the Elementor page settings you will want to make sure that the preview settings are set to the type of content and pages that you are currently working with.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.