// User Post Type

This plugin is available to Professional license holders

The User Post Type plugin lets you connect users to a post type, so that you can create user listings and filter users like any other post type 🙂

How it works

The plugin adds a new hidden upt_user post type, and adds a post for each user. It links the two via the _upt_post_id usermeta.

Setup

Browse to Settings > User Post Type and click the “Sync now” button.

As seen above, you can also copy extra data into the postmeta table. This is not required to display fields — it’s only useful if using meta_query (see below).

Displaying users

To display a list of users, use WP_Query (not WP_User_Query) like so:

$args = array(
    'post_type' => 'upt_user',
    'post_status' => 'publish',
    'posts_per_page' => 10,
);
$query = new WP_Query( $args );

To display only administrators, select “Roles” in the settings page dropdown, then Sync. Afterwards, use the field within meta_query:

$args = array(
    'post_type' => 'upt_user',
    'meta_query' => array(
        array(
            'key' => 'roles',
            'value' => 'administrator',
            'compare' => '=',
        )
    )
);
$query = new WP_Query( $args );

Displaying user fields

UPT supports WP user functions; just replace $user_id with UPT()->get_user_id().

echo get_user_meta( UPT()->get_user_id(), 'your_field_name', true );

Outside of The Loop, pass in the post ID like so:

echo get_user_meta( UPT()->get_user_id( THE_POST_ID ), 'your_field_name', true );

Adding facets

When adding a new facet via Settings > FacetWP, you’ll see a new “User Fields” section in the Data source dropdown. The following new choices are available:

  • User ID
  • User Login
  • User Email
  • User URL
  • Registration Date
  • User Status
  • Display Name
  • Roles
  • All fields within wp_usermeta

Details

  • Version: 0.4
  • Updated: Feb 6, 2018
  • Requires: FacetWP Professional 3.1+