title: Custom QueryVars and pretty URL with Wordpress
body: <p>I have working 'solution' but I'm not able to make a clean URL.</p>
  <p>My Setup:
  Two CPT 'objekte' and 'onlineauktion'.</p>
  <pre><code>   register_post_type( 'objekte',
      array(
          'labels' =&gt; array(
              'name' =&gt; __( 'Objekte'),
              'singular_name' =&gt; __( 'Objekt' )
          ),
          'public' =&gt; true,
          'has_archive' =&gt; true,
          'rewrite' =&gt; array('slug'=&gt;'objekt'),
          'capability_type' =&gt; 'page',
          'supports' =&gt; array('thumbnail', 'title', 'custom-fields', 'revisions', 'page-attributes', 'post-formats'),
          // see http://www.kevinleary.net/wordpress-dashicons-list-custom-post-type-icons/
          'menu_icon' =&gt; 'dashicons-star-filled',
          'hierarchical' =&gt; true,
      )
  );
  flush_rewrite_rules();
  
  register_post_type( 'onlineauktion',
  array(
      'labels' =&gt; array(
          'name' =&gt; __( 'Online Auktionskatalog'),
          'singular_name' =&gt; __( 'Online Auktionskatalog' )
      ),
      'public' =&gt; true,
      'has_archive' =&gt; true,
      'rewrite' =&gt; array('slug'=&gt;'onlineauktion'),
      'capability_type' =&gt; 'page',
      'supports' =&gt; array('thumbnail', 'title', 'custom-fields', 'revisions', 'page-attributes', 'post-formats'),
      // see http://www.kevinleary.net/wordpress-dashicons-list-custom-post-type-icons/
      'menu_icon' =&gt; 'dashicons-star-filled',
      'hierarchical' =&gt; true,
  )
  );
  flush_rewrite_rules();
  </code></pre>
  <p>Archivpage ('objekte'): /objekt/page_title
  That's fine.
  Archivepage ('onlineauktion') with a ACF realtionship field for 'objekte' with the same link /objekt/page_tiel but I would like to have /onlineauktion/objekt/page_title</p>
  <p>Registration of the QueryVars</p>
  <pre><code>function registerQueryVars( $vars ) {
      $vars[] = 'cm_status';
      return $vars;
  }
  add_filter( 'query_vars', 'registerQueryVars' );
  </code></pre>
  <p>Permalink on the Archivpage ('onlineauktion')</p>
  <pre><code>&lt;a class=&quot;black&quot; href=&quot;{{post.link}}{{type == 'onlineauktion' ? '?cm_status=onlineauktionen'}}&quot;&gt;
  </code></pre>
  <p>If I visit the page 'onlineauktion' i get this URL: /objekt/abgehaeutetes-rind-−-1968/?cm_status=onlineauktionen</p>
  <p>this is not working:</p>
  <pre><code>add_action('init', 'add_my_rewrite');
  function add_my_rewrite() {
      global $wp_rewrite;
      $wp_rewrite-&gt;add_rule('objekt/([^/]+)','index.php?cm_status=$matches[1]','top');
      $wp_rewrite-&gt;flush_rules(false);  // This should really be done in a plugin activation
  }
  </code></pre>
  <p>What am i missing.</p>
  <p>Thanks in advance</p>
  <p>C</p>