WordPress.org

Support

Support » How-To and Troubleshooting » Using post meta in wp_nav_menu

Using post meta in wp_nav_menu

  • stevebluck

    @stevebluck

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • vtxyzzy

    @vtxyzzy

    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?

    stevebluck

    @stevebluck

    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…

    vtxyzzy

    @vtxyzzy

    Sorry, I was thinking single.php.

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

    stevebluck

    @stevebluck

    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?

    I would also be very interested in such a solution.

    Somebody?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using post meta in wp_nav_menu’ is closed to new replies.