Created Custom Post type called members, don't need a members permalink, but need to link to member patents, if exists for member (which I got figured out).

The problem I'm facing is the creation of the ep_mask and rewrites for the endpoint here.

Basically, I create a member named, "John Doe", now want the url to be something like this for showing his patents:


but I have something like this now: member/john-doe/?patents

How do I get rid of the ? mark in the url?

register_post_type('team_member', array(
        'description'           => __('Team Members'),
        'label'                 => __('team_members'),
        'labels'                => array(
            'name'                  => _x('Team Member', 'Post Type General Name'),
            'singular_name'         => _x('Team Member', 'Post Type Singular Name'),
            'menu_name'             => __('Team Members'),
            'parent_item_colon'     => __('Parent Team Member'),
            'all_items'             => __('All Team Members'),
            'view_item'             => __('View Team Member'),
            'add_new_item'          => __('Add New Team Member'),
            'add_new'               => __('Add New'),
            'edit_item'             => __('Edit Team Member'),
            'update_item'           => __('Update Team Member'),
            'search_items'          => __('Search Team Members'),
            'not_found'             => __('Not Found'),
            'not_found_in_trash'    => __('Not Found in Trash')
        'taxonomies'            => array('department', 'team'),
        'supports'              => array('title', 'editor', 'thumbnail'),
        'rewrite'               => array('slug' => 'member', 'ep_mask' => 'patents'),
        'hierarchical'          => false,
        'public'                => false,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'show_in_nav_menus'     => false,
        'show_in_admin_bar'     => true,
        'query_var'             => true,
        'menu_position'         => 5,
        'can_export'            => true,
        'has_archive'           => false,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page'

add_filter( 'request', 'filter_request' );
function filter_request($vars)
        $vars['patents'] = true;

    return $vars;

add_action( 'template_redirect', 'catch_vars' );
function catch_vars()
    global $wp_query;

    if (!isset($wp_query->query_vars['patents']) || !is_singular())

    // Template here for Member Specific Patents!
    include_once(dirname(__FILE__) . '/single-team_member-patents.php');

How to make the endpoint a folder structure instead of a ? at end with query string?


I am using this within the init action also:

function do_stuff() {
    add_rewrite_endpoint('patents', EP_PERMALINK);
add_action('init', 'do_stuff');
  • patents isn't a valid value for ep_mask, endpoint masks are defined in the rewrite API and listed on the add_rewrite_endpoint codex page.
    – Milo
    Feb 17, 2016 at 18:36
  • How do you add another sub-level url, in this case /patents/ for a custom post type? I need it to be made available on all posts for that custom post type is this possible? So will be in the format: /members/{post-slug}/patents/ Feb 17, 2016 at 18:46
  • 2
    use add_rewrite_endpoint to add an endpoint.
    – Milo
    Feb 17, 2016 at 18:48
  • Ok, sorry, forgot to mention that I am already using that function within the init action, it is not working like a directory structure, instead it is only displaying the include when I browse to: /members/john-doe/?patents, but I need it to load on: /members/john-doe/patents/, how? Feb 17, 2016 at 18:52
  • 1
    If you only need it for the one type, then you can use add_rewrite_rule instead. The endpoint mask determines what link types the endpoint rules are added to, a non-hierarchical singular permalink isn't further differentiated.
    – Milo
    Feb 17, 2016 at 19:21

1 Answer 1


Ok, I got it, thanks for the point in the right direction guys!

add_rewrite_rule('^members/([^/]*)/([^/]*)/?', '^members/$matches[1]/?$matches[2]', 'top');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.