WordPress.org

Ready to get started?Download WordPress

Forums

Using post meta in wp_nav_menu (6 posts)

  1. stevebluck
    Member
    Posted 3 years ago #

    Hello,

    I want to display a subtitle (kicker) with each link that is generated with wp_nav_menu().

    I have created a post meta called 'kicker' and was hoping I could do something like the following:

    <?php wp_nav_menu( array('theme_location' => 'main', 'menu_class' => 'sf-menu', 'after' => get_post_meta($post->ID, "kicker", true) )); ?>

    Unfortunately this doesn't work, probably because it can't get the ID, anyone know how I can get this working?

    Thanks.

  2. vtxyzzy
    Member
    Posted 3 years ago #

    Can you save the ID of the post in a variable while in the loop, and use the variable in the call to get_post_meta?

  3. stevebluck
    Member
    Posted 3 years ago #

    Well the wp_nav_menu is not within the loop so how would I get the ID for each menu item that is generated and then use it to get_post_meta?

    Even if I created a loop, how would I matcch a menu item with the correct ID?

    It seems like I would have to create a new SQL query but have no idea how to with the new menu system...

  4. vtxyzzy
    Member
    Posted 3 years ago #

    Sorry, I was thinking single.php.

    Perhaps you can use one of the filters called in wp-includes/nav-menu.php.

  5. stevebluck
    Member
    Posted 3 years ago #

    nav-menu.php goes straight over my head, way too advanced for me to understand.

    Is anyone able to give me an example of how I could acomplish this?

  6. Net Zero
    Member
    Posted 3 years ago #

    I would also be very interested in such a solution.

    Somebody?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags