0

I have added a section to my user profiles called ArtistCategory. This can be value X or Z.

I'm using the code below to get a list, which I use in a menu and show after the artists display_name the artists ArtistsCategory. So far so good.

http://pastebin.com/jQHDjtF2

I would like to filter the query by only showing authors from ArtistsCategory X and can't get it figured out. All things I can find are post related. Hope someone can help me out on this. Thanks!

1

Is there a specific reason you aren't using WP_User_Query? It would make it easier to do what you want to. You can read up on it here.

Something along these lines would solve your problem, as far as I understand it:

$args = array(
   "meta_key" => "ArtistCategory",
   "meta_value" => "X" //or "Z"
);
$authors = new WP_User_Query($args);
if (!empty($authors)) {
   echo '<ul>';
   foreach ($authors as $author){
       //However you want to echo each author.
   }
   echo '</ul>';
} 
else {
   echo 'No authors found';
}
  • Didn't know about wp_user_query, many thanks! – AKNL Feb 26 '16 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.