• Resolved mod keys

    (@willibrown)


    My client wants a menu item to list their “events” with a submenu of past events.

    We do not need a calendar or ticketing or fancy plugin features.

    I would rather not involve a plugin.

    My thought in design approach is to just use Posts and a Category “Events” with a subcategory of “Past Events”.

    Is there a way to do this so that the items populate the menu automatically?

    Menu Hierarchy
    Events
    Upcoming Event 1
    Upcoming Event 2
    Past Events
    Past Event 1
    Past Event 2

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’ve not done this myself, but it should work. You need a hook that only fires when new posts are published, otherwise a menu item is added every time the post is edited. “draft_to_publish” action should serve nicely. Verify the post has the proper category term assigned before calling wp_update_nav_menu_item() to create a new menu item. Despite the name being for updates, it will create new items too.

    I’ve never used this function before, so cannot offer specific advice. For a list of proper data to provide, see the defaults list in the function’s source code. The same function can be used to change the title from upcoming to past at the appropriate time.

    If the referenced post is deleted, the menu item should also be removed. To remove the menu item without removing the related post, each menu item is also a post of the “nav_menu_item” type. You can remove it with wp_delete_post().

    Thread Starter mod keys

    (@willibrown)

    Thanks. I ended up using a plugin: Category Posts in Custom Menu

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Event List Development Design’ is closed to new replies.