最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

url rewriting - Unable to access the query variables in the template

matteradmin3PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far