Home › Forums › General Issues › User query based on taxonomy field
I am trying to build a user-query based on an acf taxonomy field (“fruits”):
<?php
$args = array(
'key' => 'fruits',
'value' => 'apple'
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo $user->display_name;
}
} else {
echo 'No users found.';
}
?>
but nothing happens. Any idea? Or is the a better way to do it?
Hi,
What do you want to do ? Search users with specific values on ACF fields ?
Because otherwise, WP_User_Query is a WordPress class, not ACF.
Yes i want to search users with a specific value. get it to work with normal custom fields but not with the taxonomy field used on users pages.
Ok. For this, I do as follow (excerpt from my code, so probably not perfect at all) :
foreach( $args as $key => $value ) {
$meta_query = array ( // logical operator between search field
'relation' => 'AND',
);
$meta_query[] = array(
'key' => $key,
'value' => $value,
'compare' => 'IN', // 'IN' if $value is an array, '=' for string
);
}
$wp_query = new WP_User_Query( array( 'meta_query' => $meta_query ) );
$resultats = $wp_query->get_results();
Hmmm, i have no search field i just want to show the users with the checked taxonomy field “bananas” on the page “bananas”. For this i show a taxonomy field (ACF) on every user page where the users see all categories listet. i have posts who are in the category “bananas” and i have a page with the title “bananas”. Andon this page i want to list all users who have checked the tyxonomy (category) “bananas” on their profile page.
The topic ‘User query based on taxonomy field’ is closed to new replies.
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.