How to create a child page to every post?


Is there anyway to create subpages for evey single post


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 :

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
function subpage_links_rewrite($rules){
    //add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?test.php=$matches[1]', 'top');
    $rules['([^.]+)$'] = "test.php?idtest=$matches[1]";
    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' );
Mado Mam 1 month 0 Answers 8 views 0

Leave an answer