• Hi, I’m building a theme and need help with the following:

    I have a custom post type that’s publicly queryable, so I have pages like this:
    example.com/post-type/my-post

    I need automatically generated sub-pages on which I can show a form, like this:
    example.com/post-type/my-post/form

    This is partially working now with a rewrite rule:

    add_rewrite_rule(
    '^post-type/([^/]+)/form/?$',
    'index.php?post_type=post-type&name=$matches[1]&form=1',
    'top'
    );

    And I can intercept the request in the template_redirect hook:

    if(empty(get_query_var("form"))) {
    return;
    }

    $postId = get_queried_object_id();

    (I also registered the query vars using the query_vars filter)

    Template:

    I created a custom template in Gutenberg and now I have the ID and the template available in my code:

    $templateId = 26;
    $templateName = "wp-custom-template-sample-form";

    How can I render this template / tell WordPress to do so?

    I tried the template_include hook, but it needs an absolute path to a php file which I don’t have, since it’s a Gutenberg template stored in the database.

    Or do you have any other ideas on how to build this? Maybe the whole approach is wrong.

  • You must be logged in to reply to this topic.