Title: Using multiple meta keys ?
Last modified: September 23, 2018

---

# Using multiple meta keys ?

 *  Resolved [nessler](https://wordpress.org/support/users/nessler/)
 * (@nessler)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/using-multiple-meta-keys/)
 * Hi,
 * we have added extra fields (meta keys) to our existing users:
    – users by “function”(
   photographer, editor,…) and – divided into non active and active users, grouped
   by “status”.
 * The goal would be to display two rows, the top one with active photograpers, 
   active editors, and at the bottom of the page past members.
 * we tried doing it with this shortcode but it’s not working, could anybody assist
   on what we need to alter ?
 * each of the codes below work seperately:
    [userlist meta_key=”function” meta_value
   =”photographer”] [userlist meta_key=”status” meta_value=”active”]
 * what we’re trying to achieve is a combination of both:
    [userlist meta_key=”function,
   status” meta_value=”photographer, active”] Sadly we can’t get that to work.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/using-multiple-meta-keys/#post-10716544)
 * Unfortunately, that isn’t currently supported as described, but is possible if
   you filter `sul_user_query_args` as shown in the FAQ as an alternative method
   to query by [Multiple Meta Keys](https://wordpress.org/plugins/simple-user-listing##how%20to%20create%20very%20complex%20user%20queries%20%7C%20how%20to%20query%20multiple%20meta%20keys).
 * I am open to Pull Requests on [Github](https://github.com/helgatheviking/simple-user-listing).
   I do think this would be a good addition, but it’s not something I would be able
   to add any time soon.
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/using-multiple-meta-keys/#post-10777530)
 * This _may_ get all the active photographers and editors and then all the inactive
   photographers and editors as 2 shortcodes:
 *     ```
       function sul_custom_meta_query( $args, $query_id ){
   
       	switch ( $query_id ) {
       		case 'active_meta_query':
   
       			$args['meta_query'] = array(
       				'relation' => 'OR',
       				array(
       					'key' => 'function',
       					'compare' => 'IN',
       					'value' => array( 'photographer', 'editor' ),
       				),
       				array(
       					'key' => 'status',
       					'compare' => '=',
       					'value' => 'active'
       				),
       			);
   
       		break;
   
       		case 'inactive_meta_query':
   
       			$args['meta_query'] = array(
       				'relation' => 'OR',
       				array(
       					'key' => 'function',
       					'compare' => 'IN',
       					'value' => array( 'photographer', 'editor' ),
       				),
       				array(
       					'key' => 'status',
       					'compare' => '!=',
       					'value' => 'active'
       				),
       			);
   
       		break;
   
       	}
   
       	return $args;
       }
       add_filter( 'sul_user_query_args', 'sul_custom_meta_query', 10, 2 );
       ```
   
 * You’d need to specify the query id in your shortcode like so:
    `[userlist query_id
   ="active_meta_query"]`
 * and then for the non-active folks:
 * `[userlist query_id="inactive_meta_query"]`
 * It might be possible to display _all_ the photographers and editors and then 
   group/sort them. This is totally untested though so I don’t know if it will work,
   but here’s an attempt to sort the users by the `active` meta key. This would 
   be the shortcode `[userlist query_id="my_custom_meta_query"]`. Since this function
   is named the same as the one above don’t use them both at the same time or you
   will get a fatal error.
 *     ```
       function sul_custom_meta_query( $args, $query_id ){
   
       	if( $query_id == 'my_custom_meta_query' ){ 
   
       		$args['meta_key'] = 'status';
       		$args['orderby'] = array( 'meta_value', 'display_name' );
   
       		$args['meta_query'] = array(
       			array(
       				'key' => 'function',
       				'compare' => 'IN',
       				'value' => array( 'photographer', 'editor' ),
       			)
       		);
   
       	}
   
       	return $args;
       }
       add_filter( 'sul_user_query_args', 'custom_meta_query', 10, 2 );
       ```
   
 * Good luck! Let me know if any of this works or if you find a good solution.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using multiple meta keys ?’ is closed to new replies.

 * ![](https://ps.w.org/simple-user-listing/assets/icon-256x256.png?rev=3061308)
 * [Simple User Listing](https://wordpress.org/plugins/simple-user-listing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-user-listing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-user-listing/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-user-listing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-user-listing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-user-listing/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/using-multiple-meta-keys/#post-10777530)
 * Status: resolved