Skip to content

Instantly share code, notes, and snippets.

@aliboy08
Last active September 6, 2024 10:16
Show Gist options
  • Save aliboy08/b8a6c8bacc5ee0272aa12e64e9e372e6 to your computer and use it in GitHub Desktop.
Save aliboy08/b8a6c8bacc5ee0272aa12e64e9e372e6 to your computer and use it in GitHub Desktop.
Sample Custom Page with nested different post types e.g: /broker/member-name/contact/
add_shortcode('broker_init', function(){
ob_start();
include 'broker/init.php';
return ob_get_clean();
});
add_action('init', 'custom_rewrite_rules');
function custom_rewrite_rules(){
add_rewrite_rule(
'^broker/([\w+-]*)/([\w+-]*)/?$',
'index.php?pagename=broker&broker_slug=$matches[1]&broker_page_slug=$matches[2]',
'top'
);
add_rewrite_rule(
'^broker/([\w+-]*)/?$',
'index.php?pagename=broker&broker_slug=$matches[1]',
'top'
);
}
add_filter( 'query_vars', 'custom_query_vars');
function custom_query_vars($query_vars){
$custom_vars = [
'broker_slug',
'broker_page_slug',
];
foreach( $custom_vars as $custom_var ) {
$query_vars[] = $custom_var;
}
return $query_vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment