Home Forums Front-end Issues Can i use WP_User_Query combined with taxonomy created with ACF?


Can i use WP_User_Query combined with taxonomy created with ACF?

  • Hello,

    I have added the taxonomy field to the user settings of my site.

    Each user may be assigned to one or more terms.

    I can easily loop trough my users and display their terms as an array with id’s by get_field()…

    Question is if it’s possible to add one or more terms to the WP_User_Query arguments to filter at query level?

    Like i’d only like to fetch users that belong to term id 3… ?

  • Hi @retypejonas

    I don’t believe you can use WP_User_Query for this as it is not native to add term meta to a user.

    Have you selected the ‘Save / Load value to post’ option for your taxonomy field?

    Perhaps you could perform a meta query instead?

  • What does ” ‘Save / Load value to post’ ” do?

    I looked trough the user_meta database table and noted that the serialized array that stores term id’s wraps each ID in ” and “.

    So”meta_compare, LIKE, “term-id” did the trick for now. Hopefully it will not break in the future? 😉

  • Hi @retypejonas

    The save / load option will not only save the postmeta data, but will create connections from the post to the taxnomy term. This is to replicate the functionality of a taxonomy checkbox, like the post category metabox.

    This however will not with with a user, only a post.

    Nice work on the LIKE SQL, yes, this will be the only option for now and I’ll look into why the ID’s are saving as strings.


  • Thanks elliot, lets not change the serialized array so that its not queryable 😉

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

The topic ‘Can i use WP_User_Query combined with taxonomy created with ACF?’ is closed to new replies.