0

I need to show a menu depending on what user selects on Page Options.

I take menu name from a user to a variable and now i need it to parse through wp_nav_menu.

Im trying it like this but it doesn`t work:

$var = the_field('menu2');

$params = array(
    'theme_location'  => '',
    'menu'            => $var, // <== This is what i want to do
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
);

wp_nav_menu( $params );

I have also tried

'menu'   =>  '$var'

If someone could help me i would appreciate

Thanks

1 Answer 1

1

You want get_field() (which returns the value), not the_field() (which echo's the value):

$var = get_field( 'menu2' );
0

Your Answer

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

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