How to add multiple routes
-
I call this plugin from a custom made plugin.
I’m wondering how do I make multiple routes.The routes that I’d like to set up are:
^find/practitioners/
and
^practitioners/The error I’m getting from the below code is:
Fatal error: Cannot redeclare WP_Router_Sample::generate_routes()...
Here is the plugin code so far:
// I'm adding an array as an argument with the different routes I'm trying to add add_action( 'wp_router_generate_routes', array('iabt_practitioner_find_routes', 'iabt_practitioner_results_routes', 20) ); function iabt_practitioner_find_routes( $router ) { $route_args = array( 'path' => '^find/practitioners/', 'query_vars' => array( ), 'page_callback' => 'iabt_find_practitioner_route_callback', 'page_arguments' => array( ), 'access_callback' => true, 'title' => __( 'Demo Route' ), 'template' => array( 'page.php', dirname( __FILE__ ) . '/page.php' ) ); $router->add_route( 'iabt-find-route-id', $route_args ); } function iabt_find_practitioner_route_callback( ) { return "Congrats! Your demo callback is fully functional. Now make it do something fancy"; } function iabt_practitioner_results_routes( $router ) { $route_args = array( 'path' => '^find/practitioners/', 'query_vars' => array( ), 'page_callback' => 'iabt_results_practitioner_route_callback', 'page_arguments' => array( ), 'access_callback' => true, 'title' => __( 'Returning BCST Results' ), 'template' => array( 'page.php', dirname( __FILE__ ) . '/page.php' ) ); $router->add_route( 'iabt-return-route-id', $route_args ); } function iabt_results_practitioner_route_callback( ) { return "Congrats! Your demo callback is fully functional. Now make it do something fancy"; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to add multiple routes’ is closed to new replies.