Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Maybe I am just not grasping the concept of WP right here but why is everything in Wordpress stored as a post of some type? I have a custom set of tables that house hundreds and thousands of items. I would like to programatically create a navigation menu that dynamically updates items to reflect my custom tables. I haven't been able to find a way to do this without using the following function:

wp_update_nav_menu_item()

To my understanding this function stores the item in the array in the wordpress tables as posts/taxonomies? This is needless overhead in my case and looks pretty permanent. My menu items will change pretty much on a daily basis, I don't want to grab items from one table only to have them stored in another table.

Does anyone know how I could directly update the navigation menu each time the homepage loads without requiring any interference from the administration panel?

Thanks.

share|improve this question
    
Are your menus changing each time the page is refreshed? –  Brian Fegter Oct 9 '12 at 20:35
    
to answer the question why WordPress stores menu items as posts- you can create menu items with titles that may differ from post titles, links to external content, nesting, ordering, custom css classes, etc., and the ability to have a single item appear (differently) in multiple menus. that data has to get stored somehow, it makes sense to reuse the same API to manage all of it in the same way pages, posts, tax, post meta, etc. are managed. –  Milo Oct 9 '12 at 20:52
    
Pretty much, Brian. Milo, I still don't see why you can't fetch the links directly from the source and make it appear differently at run time? Maybe I am just thinking about this too programatically. –  SPI Oct 10 '12 at 1:42
add comment

1 Answer

Filter wp_nav_menu_objects and add your custom items dynamically (see this example or this). You get the current list of items and the arguments wp_nav_menu() was with as parameters. Then you can just add new items or remove existing ones.

share|improve this answer
    
Thanks toscho, I had quite a messed up day trying to wrap my head around WP's way of manipulating things. I will try your methods in a couple of hours and hopefully end up accepting your answer :) –  SPI Oct 10 '12 at 1:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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