Question

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!

Was it helpful?

Solution

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';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top