admin管理员组

文章数量:1025477

I added a custom endpoint 'product' in the pages.

add_action( 'init', 'add_endpoints');
function add_endpoints() {
   add_rewrite( 'product', EP_PAGES );
}

I added a shortcode called `'dashboard' shortcode in a page.

add_shortcode( 'ims-dashboard', 'dashboard' );
public function dashboard() {
   global $wp_query;

   return ims_get_template_html( 'admin-panel/admin-panel.php' );

}

When i access the page https://localhost/dashboard-2/product, it is rendered correctly.

But whenever I access the page https://localhost/dashboard-2/product/add, the

Oops! That page can’t be found.

is occurred.

I want to load the different page when the url is https://localhost/dashboard-2/product/add.

I added a custom endpoint 'product' in the pages.

add_action( 'init', 'add_endpoints');
function add_endpoints() {
   add_rewrite( 'product', EP_PAGES );
}

I added a shortcode called `'dashboard' shortcode in a page.

add_shortcode( 'ims-dashboard', 'dashboard' );
public function dashboard() {
   global $wp_query;

   return ims_get_template_html( 'admin-panel/admin-panel.php' );

}

When i access the page https://localhost/dashboard-2/product, it is rendered correctly.

But whenever I access the page https://localhost/dashboard-2/product/add, the

Oops! That page can’t be found.

is occurred.

I want to load the different page when the url is https://localhost/dashboard-2/product/add.

Share Improve this question asked Apr 4, 2019 at 6:19 Sagar Bahadur TamangSagar Bahadur Tamang 1331 silver badge10 bronze badges 6
  • 2 Do you have a post type of product on your site? If so, change the name of the endpoint - e.g. to product2 .. And there's a typo in the question - it's add_rewrite_endpoint(), not add_rewrite(). – Sally CJ Commented Apr 4, 2019 at 6:52
  • It seems I did. Thanks for point it out. – Sagar Bahadur Tamang Commented Apr 4, 2019 at 6:55
  • 1 So I suppose you've also flushed the rewrite rules? – Sally CJ Commented Apr 4, 2019 at 6:56
  • 1 Yes, I missed your comment edit. So make certain that the endpoint name does not clash with a post type slug - e.g. the product in your case. – Sally CJ Commented Apr 4, 2019 at 7:02
  • 1 Thanks for the help. I will keep in mind next time. – Sagar Bahadur Tamang Commented Apr 4, 2019 at 7:25
 |  Show 1 more comment

1 Answer 1

Reset to default 0

I have WooCommerce installed. It has registered the product post type which was conflicting with it.

I renamed to endpoint and it works.

I added a custom endpoint 'product' in the pages.

add_action( 'init', 'add_endpoints');
function add_endpoints() {
   add_rewrite( 'product', EP_PAGES );
}

I added a shortcode called `'dashboard' shortcode in a page.

add_shortcode( 'ims-dashboard', 'dashboard' );
public function dashboard() {
   global $wp_query;

   return ims_get_template_html( 'admin-panel/admin-panel.php' );

}

When i access the page https://localhost/dashboard-2/product, it is rendered correctly.

But whenever I access the page https://localhost/dashboard-2/product/add, the

Oops! That page can’t be found.

is occurred.

I want to load the different page when the url is https://localhost/dashboard-2/product/add.

I added a custom endpoint 'product' in the pages.

add_action( 'init', 'add_endpoints');
function add_endpoints() {
   add_rewrite( 'product', EP_PAGES );
}

I added a shortcode called `'dashboard' shortcode in a page.

add_shortcode( 'ims-dashboard', 'dashboard' );
public function dashboard() {
   global $wp_query;

   return ims_get_template_html( 'admin-panel/admin-panel.php' );

}

When i access the page https://localhost/dashboard-2/product, it is rendered correctly.

But whenever I access the page https://localhost/dashboard-2/product/add, the

Oops! That page can’t be found.

is occurred.

I want to load the different page when the url is https://localhost/dashboard-2/product/add.

Share Improve this question asked Apr 4, 2019 at 6:19 Sagar Bahadur TamangSagar Bahadur Tamang 1331 silver badge10 bronze badges 6
  • 2 Do you have a post type of product on your site? If so, change the name of the endpoint - e.g. to product2 .. And there's a typo in the question - it's add_rewrite_endpoint(), not add_rewrite(). – Sally CJ Commented Apr 4, 2019 at 6:52
  • It seems I did. Thanks for point it out. – Sagar Bahadur Tamang Commented Apr 4, 2019 at 6:55
  • 1 So I suppose you've also flushed the rewrite rules? – Sally CJ Commented Apr 4, 2019 at 6:56
  • 1 Yes, I missed your comment edit. So make certain that the endpoint name does not clash with a post type slug - e.g. the product in your case. – Sally CJ Commented Apr 4, 2019 at 7:02
  • 1 Thanks for the help. I will keep in mind next time. – Sagar Bahadur Tamang Commented Apr 4, 2019 at 7:25
 |  Show 1 more comment

1 Answer 1

Reset to default 0

I have WooCommerce installed. It has registered the product post type which was conflicting with it.

I renamed to endpoint and it works.

本文标签: url rewritingUnable to access the query variables in the template