• I am using Advanced Custom Fields plugin and it all works.

    I am trying to have the person creating the page choose a custom menu through one of the fields and have that variable pass into the theme_location, but I cannot get it to work.

    the theme works if it is hard coded as such

    ‘theme_location’ => ‘about’,
    or
    ‘theme_location’ => ‘bicycles’,

    none of the following worked.
    ‘theme_location’ => the_field(‘product_menu’);
    ‘theme_location’ => ‘the_field(‘product_menu’);’
    ‘theme_location’ => $variable, (yes the variable was pass via $variable = the_field(‘product_menu’) and the variable echos the correct value.
    ‘theme_location’ => ‘$variable’,

    I even tried:

    if ($variable == "about") {wp_nav_menu( array( 'theme_location' => 'about' ) );}
    else if ($variable == "bicycle") {wp_nav_menu( array( 'theme_location' => 'bicycle') );}
    else if ($variable == "shoes") {wp_nav_menu( array( 'theme_location' => 'shoes' ) );}

    even tried this:

    $v1 = "about";
    $v2 = "bicycle";
    $v3 = "shoes";
    if ($variable == $v1) {wp_nav_menu( array( 'theme_location' => 'about' ) );}
    else if ($variable == $v2) {wp_nav_menu( array( 'theme_location' => 'bicycle') );}
    else if ($variable == $v3) {wp_nav_menu( array( 'theme_location' => 'shoes' ) );}

    does not work, but the variables do, but the if statement is not recognizing anything.

    what am I doing wrong???? [he asks while stands on the edge of a cliff]

    it cannot be an ACF issue as the field is working… [he says under his breath]

Viewing 1 replies (of 1 total)
  • Please change your code. Instead of the_field replace it wil get_the_field

    Example:
    'theme_location' => get_the_field('product_menu');

Viewing 1 replies (of 1 total)
  • The topic ‘theme_location variable and if statement’ is closed to new replies.