<?php
/**
 * Register query vars part
 *
 * @param  array  $vars  The array of available query variables
 *
 * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
 */

class AuctionParts
{
    public function init()
    {
        add_filter('query_vars', array($this, 'auctions_register_query_vars'));
        add_action('init', array($this, 'auctions_do_rewrite'));
    }

    function auctions_do_rewrite(){
        add_rewrite_rule('^auction/([^/]*)/part/([^/]*)/page/([0-9]{1,})/?', 'index.php?auction_number=$matches[1]&part=$matches[2]&paged=$matches[3]','top');
        add_rewrite_rule('^auction/([^/]*)/part/([^/]*)/?', 'index.php?auction_number=$matches[1]&part=$matches[2]','top');
    }

    public function auctions_register_query_vars($vars)
    {
        $vars[] = 'part';
        return $vars;
    }
}

$instance = new AuctionParts();
$instance->init();
