0

I want to automatically generate some menu items using a script (i.e. using wp_update_nav_menu_item).

This would usually be a one-off event but I might want to repeat it if the menu items need re-generating.

I guess I could write the script then manually include it in functions.php when I want it to run. Is there a better way?

1 Answer 1

0

Use the WP database (via proper methods) to store a 'is this the first run' flag?

Then just conditionally execute.

  1. check for flag in wp db
  2. if exist do nothing
  3. if not exist
  4. create me my menus dag nammit
  5. remember to set flag for next round so its only done once

Something like that?

If you need to regenerate then just flip the flag from within the code that decides if the menus need regenerating.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.