0
votes

What am I doing wrong? Just to warn you this is my first attempt at php so pardon my ignorance ;)

Currently using Wordpress with a plugin called Advanced Custom Fields. Which allows you to create custom field options in the backend of wordpress.

http://plugins.elliotcondon.com/advanced-custom-fields/

I am trying to get a div to hide if the value of the Advanced Custom Field "Available" (which is a select list) is set to "No". The div is a marker for the 10 available apartments that overlays a map. Currently it displays all 10 markers whether it's availability is set to "No" or "Yes".

$i = 201;
$available = get_field('available');

while ($i <= 210) :
  if ($available == 'No') {
    echo '<div id="apt-' . $i . '" class="map-marker" style="display:none;"></div>';
  } elseif ($available) {
    echo '<div id="apt-' . $i . '" class="map-marker">';
    echo  $i++;
    echo'</div>';
  }
endwhile;
1
Your example code doesn't show the mechanism you are using to change the value of $available - Shad
If I am understanding correctly, I am using the Wordpress plugin: Advanced Custom Fields to set the value from the backend of Wordpress. - Daniel
what happens right now? is everything shown or everything hidden? have you tried doing a var_dump() on available? - nathan gonzalez
Everything is displayed right now and no I have not yet done a var_dump, I don't even know what that is... looking it up - Daniel

1 Answers

0
votes

what are you trying to accomplish here? the get_field function is a per post in the loop method, so you would need to be iterating over the whole posts collection with the

while ($loop->have_posts()) : $loop->the_post();

if you're not using a custom loop you would leave off the $loop-> part.

you probably need to post the whole page template. you might just need to do some studying on wordpress about the loop and how it works.