0

I am trying to use the Advanced Custom Fields "True/False" plugin for Wordpress to display varied content depending on the user's referral ID.

1) If there is a Ref. ID & "Create" is True, display "Paid Nav" 2) If there is a Ref. ID & "Create" is False, display "Main Nav" 3) If anything else, show nothing.

Everything is working properly, except Item #1. When the True/False is enabled, BOTH Navigation Menus appear.

<?php while(the_repeater_field('referrers', 'options')): ?>         
    <?php if(isset($_COOKIE['referrer']) && get_sub_field('create') == true) {
        $referrer    = json_decode(stripslashes($_COOKIE['referrer']));
            echo wp_nav_menu( array('container' => false, 'menu' => 'Paid Nav' ) );

} elseif(isset($_COOKIE['referrer']) && get_sub_field('create') == false) {
        $referrer    = json_decode(stripslashes($_COOKIE['referrer']));
            echo wp_nav_menu( array('container' => false, 'menu' => 'Main Nav' ) );

} else {
echo '';

}?>
<?php endwhile; ?>
hexacyanide
  • 88,222
  • 31
  • 159
  • 162

2 Answers2

0

The problem is that you have the show menu inside the loop. What may be happening is that in one moment it shows the first one, and in another, the second one. Here is a different way to code it:

<?php
if(isset($_COOKIE['referrer'])):
  $menu_to_display = 'Main Nav';
  $referrer    = json_decode(stripslashes($_COOKIE['referrer']));
  while(the_repeater_field('referrers', 'options')):
    if(get_sub_field('create'))
      $menu_to_display = 'Paid Nav';
  endwhile;
  echo wp_nav_menu( array('container' => false, 'menu' => $menu_to_display ) );
endif;
?>

In this way, the menu is shown only once, and for only one menu. Also, it uses fewer tests. Home it helps.

SidFerreira
  • 551
  • 3
  • 20
  • It definitely helps, but I realized I need to alter my strategy. If there is a Ref. ID & "Create" is true, show "Paid Nav." Otherwise, always show "Main Nav." --- any thoughts? – user2967286 Nov 08 '13 at 21:38
0

Like this?

<?php
  $menu_to_display = 'Main Nav';
  if(isset($_COOKIE['referrer'])):
    $referrer    = json_decode(stripslashes($_COOKIE['referrer']));
    while(the_repeater_field('referrers', 'options')):
      if(get_sub_field('create'))
        $menu_to_display = 'Paid Nav';
    endwhile;
  endif;
  echo wp_nav_menu( array('container' => false, 'menu' => $menu_to_display ) );
?>
SidFerreira
  • 551
  • 3
  • 20