woocommerce offtopic - How to update permalink programmatically?

admin2025-01-07  5

After activating my plugin I should go to settings -> permalinks and click on the Save button to make custom endpoints ( for my-account page ) work. How can I do it programmatically? ( I used flush_rewrite_rules but it didn't work. )

After activating my plugin I should go to settings -> permalinks and click on the Save button to make custom endpoints ( for my-account page ) work. How can I do it programmatically? ( I used flush_rewrite_rules but it didn't work. )

Share Improve this question edited Sep 24, 2020 at 7:01 Gufran Hasan 6857 silver badges20 bronze badges asked Sep 14, 2020 at 14:12 amiwebdevamiwebdev 12 bronze badges 3
  • Where/when did you call flush_rewrite_rules? Keep in mind that this function shouldn't be called on every page load as it changes the database, can you include the code you used to try this? – Tom J Nowell Commented Sep 14, 2020 at 14:39
  • The problem was not flush_rewrite_rules . Problem caused from : Instead of adding custom endpoint one time on activation, i was doing it everytime. So one time flush_rewrite_rules could not handle it. – amiwebdev Commented Sep 24, 2020 at 7:11
  • can you post your solution as an answer along with the change you made in code? Comments can't be marked as the correct answer or upvoted for points – Tom J Nowell Commented Sep 24, 2020 at 10:01
Add a comment  | 

1 Answer 1

Reset to default 0

flush_rewrite_rules should only be called on the plugin activation OR after you update or add rewrite rules programatically.

If it does not work after verifying this, there is some other issue on your site. Make sure you are not calling flush_rewrite_rules in constructor or somewhere else on every page load.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265593a1057.html

最新回复(0)