• I have a custom query (actually two) setup for a user list. However I need to also filter down the list by member status which is found in a different table; $pmpro_memberships_users but I am not the best at coding and am having trouble using anything but $usermeta values to create my custom query. Any help would be greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    Hi there. Unfortunately, I don’t have any availability for custom jobs at the moment. But there is a section in the FAQ which covers “pseudo roles” for membership plugins:
    https://www.ads-software.com/plugins/nav-menu-roles/

    And here’s an example of how that is used with WooCommerce memberships:
    https://github.com/helgatheviking/nav-menu-roles-woocommerce-memberships

    I hope that helps!

    Thread Starter cluckingaround

    (@cluckingaround)

    Yes. Actually I think I came to a similar solution myself. wp_capabilities has the roles and I have setup roles to correspond to member levels which I can then add as criteria for the SUL. Thanks

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Wow, sorry, I thought you were using nav menu roles. I must need more caffeine. But if your memberships have a custom capability, that might work.

    Thread Starter cluckingaround

    (@cluckingaround)

    No worries. Thanks for the quick response. I think this should work so long as my roles stay in sync with membership levels (not sure that is going to happen but I will cross that bridge later I guess).

    Next challenge is to try and figure out how to create check boxes to filter the list to those who have field arrays that contain the check box value.
    ex. check box for red, white, and blue … blue and white checked … any user with either blue or white or both in the field for color is included in the list. Not sure this is possible given my skills but I am going to try.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Well SUL is set up specifically for WP users and relies completely on WP_User_Query : https://codex.www.ads-software.com/Class_Reference/WP_User_Query so anything you can do with that you can do with SUL.

    I have a filter in SUL called sul_user_query_args that lets you modify the arguments you are sending to WP_User_Query. But, for really complex queries (like in your case where you probably need custom SQL to link the tables) you need to get into pre_get_users.

    Here’s a tutorial on pre_get_users.
    https://rudrastyh.com/wordpress/pre_user_query.html

    SUL also lets you pass a query_id so that you can then customize pre_get_users on a per shortcode basis.

    So if you used this shortcode:

    
    [userlist query_id="my_custom_query"]
    

    You could then customize your user query. I *think* you would need to modify the “from” and “where” parts of the query, but I couldn’t tell you the exact SQL you’d need. The above tutorial has some good examples though.

    
    add_action('pre_user_query', 'kia_get_members' );
     
    function kia_get_members( $u_query ) {
     
     	if( isset( $u_query->query_id ) && $u_query->query_id == 'my_custom_query' ) {
    			$u_query->query_from .= 'add some custom SQL here';
                            $u_query->query_where .= 'add some custom SQL here';
     	}
    	
    }
    

    Good luck! If you figure it all out, please post your results.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Query with Non Usermeta Table’ is closed to new replies.