title: add_rewrite_rule not working with custom post type
body: <p>I am trying to follow the examples in the wordpress documentation about <a href="https://developer.wordpress.org/reference/functions/add_rewrite_rule/" rel="nofollow noreferrer">add_rewrite_rule</a> and <a href="https://developer.wordpress.org/reference/functions/add_rewrite_tag/" rel="nofollow noreferrer">add_rewrite_tag</a>.</p>
  <p>I'm using a custom post type called &quot;<strong>panel</strong>&quot;.
  so the pages look like &quot;<strong>site.com/panel/post-slug</strong>&quot;</p>
  <p>url queries work: for example I have <strong>2</strong>:
  <strong>var1 and testquery</strong>.</p>
  <p>if I go to &quot;<strong>/panel/test-page-auto/?var1=10</strong>&quot;</p>
  <p><a href="https://i.stack.imgur.com/I8Jsu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I8Jsu.png" alt="enter image description here" /></a></p>
  <p>And with var1 and testquery:</p>
  <p><a href="https://i.stack.imgur.com/xNeN2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xNeN2.png" alt="enter image description here" /></a></p>
  <p>so what i want is, change the <strong>/panel/test-page-auto/?var1=10&amp;testquery=Hi</strong>
  -&gt; <strong>/panel/test-page-auto/10/Hello</strong></p>
  <p>my code:</p>
  <pre><code>add_action('init', '__rewrite_tag_rule', 10, 0);
  function __rewrite_tag_rule() {
      
  $page_type = &quot;^panel/&quot;; 
  
  add_rewrite_tag('%testquery%', '([^&amp;]+)');
  add_rewrite_tag('%var1%', '([^&amp;]+)');
  
  //Add rule  
  //panel/test-page-auto/10/edit
  add_rewrite_rule( 
      $page_type.&quot;test-page-auto/([^/]*)/([^/]*)/?&quot;, 
      'index.php?pagename=test-page-auto&amp;var1=$matches[1]&amp;testquery=$matches[2]',
      'top' ); 
  //add rule for show
  //panel/test-page-auto/10    
      add_rewrite_rule( 
      $page_type.&quot;test-page-auto/([^/]*)/?&quot;, 
      'index.php?pagename=test-page-auto&amp;var1=$matches[1]&amp;testquery=Hi',
      'top' );
      }
  
      add_filter('query_vars', function($vars) {
      $vars[] = &quot;testquery&quot;;
      $vars[] = &quot;var1&quot;;
      return $vars;
   });
  </code></pre>
  <p>But it's not working.</p>
  <p>when I try to put <strong>/panel/test-page-auto/10/Hi</strong> it just redirects me to <strong>/panel/test-page-auto</strong> and the queries are blank.</p>
  <p>Can someone help me understand what I'm doing wrong?</p>
  <p>I have already tried:</p>
  <ul>
  <li>save permalinks after each change.</li>
  <li>edit the rules in various ways.</li>
  <li>test the links using the queries and they are working.</li>
  </ul>