I am using Wordpress and trying to create some boxes retrieving information from Adanvec Customs Fields on a custom post type.
I have this code:
<div class="col-sm-2 hidden-xs">
<?php
$box1 = get_front_page_box("Box 1");
$style_front = get_box_style($box1->ID, "front");
echo $box1->ID;
?>
<div id="front-box-1" class="front-box height-low <?php echo $box1->ID; if(has_back_panel($box1->ID)) echo "flip"; ?>">
<div class="front" style="<?php echo $style_front; ?>"><a href="#">Banana</a></div>
<?php
if(has_back_panel($box1->ID)):
$style_back = get_box_style($box1->ID, "back");
?>
<div class="back" style="<?php echo $style_back; ?>"></div>
<?php endif; ?>
</div>
</div>
<div class="col-sm-5 hidden-xs">
<?php
$box2 = get_front_page_box("Box 2");
$style_front = get_box_style($box2->ID, "front");
echo $box2->ID;
?>
<div id="front-box-2" class="front-box height-low <?php echo $box2->ID; if(has_back_panel($box2->ID)) echo "flip"; ?>">
<div class="front" style="<?php echo $style_front; ?>"><a href="#">Banana</a></div>
<?php
if(has_back_panel($box2->ID)):
$style_back = get_box_style($box2->ID, "back");
?>
<div class="back" style="<?php echo $style_back; ?>"></div>
<?php endif; ?>
</div>
</div>
And these functions:
function get_front_page_box($name) {
$args = array(
'post_title' => $name,
'post_type' => 'front-page-box',
'post_status' => 'publish'
);
$box_array = get_posts($args);
$box = $box_array ? $box_array[0] : false;
print_array($box);
return $box;
}
function get_box_style($id, $side) {
$style = "";
if(get_field($side."_panel_background_color", $id)) $style = "background-color:".get_field($side."_panel_background_color", $id).";";
return $style;
}
But for some reason both boxes have the same details (both from Box 2).
Any idea why these are returning the same info? Both posts ("Box 1" and "Box 2" exist under the front-page-box
custom post type.