简体   繁体   中英

PHP, Advanced Custom Fields, Wordpress, if statement

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM