• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Code Snippets » Add custom user view to Users > All Users

Add custom user view to Users > All Users

Chad Butler · Oct 14, 2022 ·

/**
 * This adds a custom query that can be used in the Users > All Users filtered views.
 * 
 * Set the variables according to comments noted in the snippet.  You will need to 
 * set values for the $view_name (a unique slug), $meta_key, and $meta_value as
 * noted below. 
 */
add_filter( 'wpmem_query_where', function( $query_where, $show ) {
    
    // Set these accordingly:
    
    // The view name: 
    $view_name  = 'my_unique_view_name';
    
    // The meta key of the field you are filtering by:
    $meta_key   = 'my_field_meta_key';
    
    // The value of the field you want to filter by:
    $meta_value = 'the field value';
    
    // Don't change this:
    $query_where = wpmem_add_query_where( $query_where, $view_name, $meta_key, $meta_value );
    return $query_where;
}, 10, 2 );


/**
 * This adds the link for the custom query you created above.
 * 
 * Similar to the snippet above, you'll need to set the variable values
 * to be used.  Note that some of them need to be the same as what you
 * set in the above snippet (the field name and value and the filter name).
 */
add_filter( 'wpmem_views_users', function( $views, $show ) {
    
    // Displayed value of your filter link in Users > All Users
    $name = "My Filter View";
    
    // Custom view name (should match $view_name used above)
    $view_name = "my_unique_view_name";
    
    // The meta key of the field you are filtering by (should
    // match what you're using above, this is for the count)
    $meta_key   = 'my_field_meta_key';
    
    // The value of the field you want to filter by (should
    // match what you're using above, this is for the count)
    $meta_value = 'the field value';
    
    // Don't change this:
    $views = wpmem_add_user_view_link( $views, $name, $view_name, $meta_key, $meta_value );
    return $views;
}, 10, 2 );

Not sure what to do with this code?

You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.

Here are some free articles to get you started:

  • Using Code Snippets from the Site
  • Using a code snippets plugin
  • The functions.php File
  • Create a plugin file for custom functions
  • Create a child theme
  • Do not modify plugin files!

For "hands on" help, consider a plugin support subscription or the Pro Bundle.

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy