How to create a child page to every post?

Question

Is there anyway to create subpages for evey single post

example

Page1 Url = the_permalink($post_id)."/page1";
Page2 Url = the_permalink($post_id)."/page1/page2";

and these pages will be accessible if certain meta_box value is in/true

Note :

according to this question :
Subdomains to pages

now i understood this step :

add_action('page_rewrite_rules','my_page_rules');
function ($rules){
$rules['([^/]+)/?$'] = 'test.php?pagename=pageslug /$matches[1]';
return $rules;
}

but can’t exactly how to complete it in this step :

add_filter( 'page_link', 'sub_page_link');
function sub_page_link(){
// preg_replace here
}

I can’t exactly understand how to create the link till now ?

Here is where i stoped

in function.php

//test rewrite rules
add_action('subpage_links_rewrite','my_page_rules');
function subpage_links_rewrite($rules){
    //add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?test.php=$matches[1]', 'top');
    $rules['([^.]+)$'] = "test.php?idtest=$matches[1]";
    //print_r($rules);
    return $rules;
}

add_filter( 'subpage_links_rewrite', 'sub_page_link');
function sub_page_link(){
    // preg_replace here
    $slug = preg_replace('#[^0-9a-z_-]#i', '', $_GET['idtest']);
    $link_to_convert = subpage_links_rewrite($slug);
    add_rewrite_rule( '/test20$', $link_to_convert , 'top' );
}
0
Mado Mam 5 months 2020-12-18T01:10:32-05:00 0 Answers 8 views 0

Leave an answer

Browse
Browse