Skip to main content
added 16 characters in body
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

Yes you can do this with a custom rewrite. I am doing the same for a custom post type, in my case profile.

So my urlURL = domain.com/profile/some-custom-slugdomain.com/profile/some-custom-slug. 
Dynamically I create /meet-me/meet-me behind it, so it becomes domain.com/profile/some-custom-slug/meet-medomain.com/profile/some-custom-slug/meet-me.

The real address of the contact page is domain.com/profile/some-custom-slug/?meet=truedomain.com/profile/some-custom-slug/?meet=true (or something else unique).

function wpse343933_todo() {
    add_rewrite_rule( 'city/([^/]*)/(things-to-do)/?$', 'index.php?post_type=city&name=$matches[1]&subpage=$matches[2]', 'top' );
}
add_filter( 'init', 'wpse343933_todo', 1, 3 );

The code should be placed in functions.phpfunctions.php.

Now we've only made the address 'reachable', but it shows the singular post.

In your singular.phpsingular.php you need to add an ifif statement to 'catch' this new variable.

The code for this is real easy:

if ( true == get_query_var( 'meet' ) {
    // output content for this particular 'sub page'
} else {
    // output content for the 'normal post'
}

I think this should do the trick.

Yes you can do this with a custom rewrite. I am doing the same for a custom post type, in my case profile.

So my url = domain.com/profile/some-custom-slug. Dynamically I create /meet-me behind it, so it becomes domain.com/profile/some-custom-slug/meet-me.

The real address of the contact page is domain.com/profile/some-custom-slug/?meet=true (or something else unique).

function wpse343933_todo() {
    add_rewrite_rule( 'city/([^/]*)/(things-to-do)/?$', 'index.php?post_type=city&name=$matches[1]&subpage=$matches[2]', 'top' );
}
add_filter( 'init', 'wpse343933_todo', 1, 3 );

The code should be placed in functions.php.

Now we've only made the address 'reachable', but it shows the singular post.

In your singular.php you need to add an if statement to 'catch' this new variable.

The code for this is real easy:

if ( true == get_query_var( 'meet' ) {
    // output content for this particular 'sub page'
} else {
    // output content for the 'normal post'
}

I think this should do the trick.

Yes you can do this with a custom rewrite. I am doing the same for a custom post type, in my case profile.

So my URL = domain.com/profile/some-custom-slug. 
Dynamically I create /meet-me behind it, so it becomes domain.com/profile/some-custom-slug/meet-me.

The real address of the contact page is domain.com/profile/some-custom-slug/?meet=true (or something else unique).

function wpse343933_todo() {
    add_rewrite_rule( 'city/([^/]*)/(things-to-do)/?$', 'index.php?post_type=city&name=$matches[1]&subpage=$matches[2]', 'top' );
}
add_filter( 'init', 'wpse343933_todo', 1, 3 );

The code should be placed in functions.php.

Now we've only made the address 'reachable', but it shows the singular post.

In your singular.php you need to add an if statement to 'catch' this new variable.

The code for this is real easy:

if ( true == get_query_var( 'meet' ) {
    // output content for this particular 'sub page'
} else {
    // output content for the 'normal post'
}

I think this should do the trick.

Source Link
Beee
  • 563
  • 3
  • 16

Yes you can do this with a custom rewrite. I am doing the same for a custom post type, in my case profile.

So my url = domain.com/profile/some-custom-slug. Dynamically I create /meet-me behind it, so it becomes domain.com/profile/some-custom-slug/meet-me.

The real address of the contact page is domain.com/profile/some-custom-slug/?meet=true (or something else unique).

function wpse343933_todo() {
    add_rewrite_rule( 'city/([^/]*)/(things-to-do)/?$', 'index.php?post_type=city&name=$matches[1]&subpage=$matches[2]', 'top' );
}
add_filter( 'init', 'wpse343933_todo', 1, 3 );

The code should be placed in functions.php.

Now we've only made the address 'reachable', but it shows the singular post.

In your singular.php you need to add an if statement to 'catch' this new variable.

The code for this is real easy:

if ( true == get_query_var( 'meet' ) {
    // output content for this particular 'sub page'
} else {
    // output content for the 'normal post'
}

I think this should do the trick.