• Resolved nessler

    (@nessler)


    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

    (@helgatheviking)

    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.

    I am open to Pull Requests on Github. 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

    (@helgatheviking)

    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.