0

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;
7
  • Your example code doesn't show the mechanism you are using to change the value of $available Commented Dec 10, 2011 at 3:22
  • If I am understanding correctly, I am using the Wordpress plugin: Advanced Custom Fields to set the value from the backend of Wordpress. Commented Dec 10, 2011 at 3:51
  • what happens right now? is everything shown or everything hidden? have you tried doing a var_dump() on available? Commented Dec 10, 2011 at 3:59
  • tardis1.tinygrab.com/grabs/… Commented Dec 10, 2011 at 4:00
  • 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 Commented Dec 10, 2011 at 4:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much - You're right. Dumb mistake. Adding it to the loop worked great!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.