title: Custom permalink with dynamic rewrite tags on a Wordpress custom post type
body: <p>I have a custom post type named <code>location</code> and I'm trying to set posts of this type as children of existing pages, to achieve a permalink structure like this:</p>
  
  <pre><code>example.com/alabama  &lt;-- Page with generic content
  example.com/alabama/locations  &lt;-- Another page, child of a state page
  example.com/alabama/locations/location-name  &lt;- Custom type, child of alabama/locations seen above and titled `Location Name`
  </code></pre>
  
  <p>The closest I've got to create hierarchical relationships between two distinct post types was through a meta box where I can assign a post ID as the <code>post_parent</code> of my custom type posts when saving them. However despite the page ID being indeed saved to the CPT <code>post_parent</code> field, it has no effect on the permalinks. They are coming as defined in the <code>rewrite</code> CPT option. But I don't know how to make the <code>['rewrite']['slug']</code> option dynamic, or if it's even possible.</p>
  
  <p>This is how my post type is being defined:</p>
  
  <pre><code>add_action( 'init', function() {
    register_post_type( 'location', [
      'label' =&gt; 'Location',
      'menu_icon' =&gt; 'dashicons-location-alt',
      'supports' =&gt; [ 'title', 'editor', 'custom-fields' ],
      'public' =&gt; true,
      'hierarchical' =&gt; false,
      'has_archive' =&gt; false,
      'rewrite' =&gt; false,
    ] );
  } );
  </code></pre>
  
  <p>How can I configure the rewrite rules for locations to get the permalinks I need?</p>